c:/Users/efeyhl/devs/math2/basic_math.h File Reference

basic math C++ functions and classes More...

#include "c_basic_math.h"

Go to the source code of this file.

Functions

void printBMStatus (const BM_STATUS bms, FILE *file=(FILE *) 0)
 prints a basic math status (BM_STATUS) to file
bool isValidValue (const double *value, BM_STATUS *bms=(BM_STATUS *) 0)
 tests for a valid 64 bit floating point value (double)
bool isValidValue (const __int64 *value, BM_STATUS *bms=(BM_STATUS *) 0)
 tests for a valid 64 bit integer (__int64)
double x_add_y (const double augend, const double addend, BM_STATUS *bms=NULL)
 safe addition
__int64 x_add_y (const __int64 augend, const __int64 addend, BM_STATUS *bms=NULL)
 safe addition
double x_sub_y (const double minuend, const double subtrahend, BM_STATUS *bms=NULL)
 safe subtraction
__int64 x_sub_y (const __int64 minuend, const __int64 subtrahend, BM_STATUS *bms=NULL)
 safe subtraction
double x_mul_y (const double multiplier, const double multiplicand, BM_STATUS *bms=NULL)
 safe multiplication
__int64 x_mul_y (const __int64 multiplier, const __int64 multiplicand, BM_STATUS *bms=NULL)
 safe multiplication
double x_div_y (const double numerator, const double denominator, BM_STATUS *bms=NULL)
 safe division
__int64 x_div_y (const __int64 numerator, const __int64 denominator, BM_STATUS *bms=NULL)
 safe division
double x_mod_y (const double numerator, const double denominator, BM_STATUS *bms=NULL)
 safe modulo
__int64 x_mod_y (const __int64 numerator, const __int64 denominator, BM_STATUS *bms=NULL)
 safe modulo
double reciproc_x (const double value, BM_STATUS *bms=NULL)
 safe reciproc (1/x)
double Ceil (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 Calculates the ceiling of value.
double Floor (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 Calculates the floor of value.
__int64 toInt64 (const double value, double *intDbl=(double *) 0, BM_STATUS *bms=(BM_STATUS *) 0)
 strips the decimal places from value and returns the integer (__int64)
double toDouble (const __int64 value)
 converts value to a value in double format
double Round (const double value, const int decPlaces=0, BM_STATUS *bms=(BM_STATUS *) 0)
 rounds value to a specified number of decimal places
int Compare (const double value1, const double value2, const double diff=NANO, BM_STATUS *bms=(BM_STATUS *) 0)
 compares value1 with value2
int Compare (const __int64 value1, const __int64 value2, const __int64 diff=0)
 compares value1 with value2
int isEven (const __int64 value)
 returns 1 if value is even (.. -4, -2, 0, +2, +4, ..)
double Positive (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the absolute value of value
__int64 Positive (const __int64 value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the absolute value of value
double Negative (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the negative absolute value of value
__int64 Negative (const __int64 value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the negative absolute value of value
double InvertSign (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 inverts the sign of value
__int64 InvertSign (const __int64 value, BM_STATUS *bms=(BM_STATUS *) 0)
 inverts the sign of value
double x_pow_2 (const double base, BM_STATUS *bms=NULL)
 safe square (power 2)
__int64 x_pow_2 (const __int64 base, BM_STATUS *bms=NULL)
 safe square (power 2)
double x_pow_3 (const double base, BM_STATUS *bms=NULL)
 safe cube (power 3)
__int64 x_pow_3 (const __int64 base, BM_STATUS *bms=NULL)
 safe cube (power 3)
double x_pow_4 (const double base, BM_STATUS *bms=NULL)
 safe power 4
__int64 x_pow_4 (const __int64 base, BM_STATUS *bms=NULL)
 safe power 4
double x_pow_y (const double base, const double exponent, BM_STATUS *bms=(BM_STATUS *) 0)
 safe power, calculates base pow exponent
__int64 x_pow_y (const __int64 base, const __int64 exponent, BM_STATUS *bms=(BM_STATUS *) 0)
 safe power, calculates base pow exponent
double x_root_2 (const double radicand, BM_STATUS *bms=(BM_STATUS *) 0)
 safe square root
__int64 x_root_2 (const __int64 radicand, BM_STATUS *bms=(BM_STATUS *) 0)
 safe square root
double x_root_3 (const double radicand, BM_STATUS *bms=(BM_STATUS *) 0)
 safe cube root
double x_root_4 (const double radicand, BM_STATUS *bms=(BM_STATUS *) 0)
 safe 4th root
double x_root_y (const double radicand, const double rootExponent, BM_STATUS *bms=(BM_STATUS *) 0)
 safe exp-th root
__int64 x_root_y (const __int64 radicand, const __int64 rootExponent, BM_STATUS *bms=(BM_STATUS *) 0)
 safe exp-th root
double log_b_x (const double base, const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 returns the base-logarithm of value
__int64 log_b_x (const __int64 base, const __int64 value, BM_STATUS *bms=(BM_STATUS *) 0)
 returns the base-logarithm of value
void sortAscendant (double *values, const unsigned long count, BM_STATUS *bms=(BM_STATUS *) 0)
 sorts an array of values in ascendant order
void sortAscendant (__int64 *values, const unsigned long count, BM_STATUS *bms=(BM_STATUS *) 0)
 sorts an array of values in ascendant order
long solveP1norm (double *xr, const double *pf)
 solves the normalized polynom function of first degree
long solveP1 (double *xr, const double *pf)
 solves the polynom function of first degree
long solveP2norm (double *xr, const double *pf)
 solves the normalized polynom function of second degree
long solveP2 (double *xr, const double *pf)
 solves the polynom function of second degree
long solveP3norm (double *xr, const double *pf)
 solves the normalized polynom function of third degree
long solveP3 (double *xr, const double *pf)
 solves the polynom function of third degree
long solveP4norm (double *xr, const double *pf)
 solves the normalized polynom function of fourth degree
long solveP4 (double *xr, const double *pf)
 solves the polynom function of fourth degree
long getPolyFactors1 (double *pf, const double *xz)
 calculates the polynom factors of the given zero condition(s)
BM_STATUS getPolyFactors2 (double *pf, const double *xz)
 calculates the polynom factors of the given zero condition(s)
BM_STATUS getPolyFactors3 (double *pf, const double *xz)
 calculates the polynom factors of the given zero condition(s)
BM_STATUS getPolyFactors4 (double *pf, const double *xz)
 calculates the polynom factors of the given zero condition(s)
double deg2Rad (const double degree, BM_STATUS *bms=(BM_STATUS *) 0)
 converts degree into radian
double rad2Deg (const double radian, BM_STATUS *bms=(BM_STATUS *) 0)
 converts radian into degree
double stringToDbl (const char *stringValue, BM_STATUS *bms=(BM_STATUS *) 0)
 converts stringValue into double
__int64 stringToInt64 (const char *stringValue, char **stopChar=(char **) 0, BM_STATUS *bms=(BM_STATUS *) 0)
 converts stringValue into __int64
double strToDbl (const char *str, BM_STATUS *bms=NULL)
 converts a null terminated string into a 80 bit floating point value (double)
BM_STATUS solveL1 (double *xr, const double *lf)
 solves the linear equation with 1 unknown value
BM_STATUS solveL2 (double *xr, double *lf[2])
 solves the linear equations with 2 unknown values
void printBitpattern (double value, FILE *file=(FILE *) 0)
 prints the bitpattern of a double value in hex format
void printBitpatternFormatted (double value, FILE *file=(FILE *) 0)
 prints the formatted bitpattern of a double value (sign mantisse exponent)
double sinus (const double rad, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the sinus of rad (value in rad)
double arcSin (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the arcus sinus of value [-1 .. +1]
double cosinus (const double rad, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the cosinus of rad (value in rad)
double arcCos (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the arcus cosinus of value [-1 .. +1]
double tangent (const double rad, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the tangent of rad
double arcTan (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the arcus tangent of value
double cotangent (const double rad, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the cotangent of rad
double arcCot (const double value, BM_STATUS *bms=(BM_STATUS *) 0)
 calculates the arcus cotangent of value
int Find (const double *element1, const unsigned int maxElements, const double elem)
 looks for a same element in the array
int Find (const __int64 *element1, const unsigned int maxElements, const __int64 elem)
 looks for a same element in the array

Detailed Description

basic math C++ functions and classes

This file contains all C++ functions and classes for safe numerical mathematical operations


This is the C++ wrapper for c_basic_math.h

Author:
Eckhardt Feyhl (2010 Nov. 13)

Function Documentation

double arcCos ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the arcus cosinus of value [-1 .. +1]

result = acos( value )

Parameters:
value [-1 .. +1]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of [0 .. +PI]
bms->trigonArcErr will be set if value is out of range.
If value < -1.0 this function returns PI
If value > +1.0 this function returns 0
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double arcCot ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the arcus cotangent of value

result = acot( value );

Returns:
the result of this operation in double format
The result will be in range of [0 .. +PI]
Hint:
Calculation:
if value < 0
result = acot( value ) = atan2( 1, value ) + PI
if value >= 0
result = acot( value ) = atan2( 1, value )
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double arcSin ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the arcus sinus of value [-1 .. +1]

result = asin( value )

Parameters:
value [-1 .. +1]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of [-PI/2 .. +PI/2]
bms->trigonArcErr will be set if value is out of range.
If value < -1.0 this function returns -PI/2
If value > +1.0 this function returns +PI/2
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double arcTan ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the arcus tangent of value

result = atan( value )

Parameters:
value [-numType_MAX .. +numType_MAX]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of ]-PI/2 .. +PI/2[
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double Ceil ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

Calculates the ceiling of value.

Calculates the smallest integer that is greater than or equal to value before calling this method

Returns:
the integer value in double format
The result will be in range of the data type numType
Hint:
This method uses the standard C function ceil().
Examples:
double value = 2.1;
double result = Ceil(value);
printf("\n ceil of %f = %f", value, result);
value = -2.9;
result = Ceil(value);
printf("\n ceil of %f = %f", value, result);
Outputs:
ceil of 2.1 = 3.0
ceil of -2.9 = -2.0
int Compare ( const __int64  value1,
const __int64  value2,
const __int64  diff = 0 
)

compares value1 with value2

Parameters:
value1 the first value compared with value2
value2 the second value to be compared with value1
diff difference to detect value1 != value2
Returns:

-1, if value1 is less than value2
0, if value1 is equal with value2
+1, if value1 is greater than value2
int Compare ( const double  value1,
const double  value2,
const double  diff = NANO,
BM_STATUS bms = (BM_STATUS*)0 
)

compares value1 with value2

Parameters:
value1 the 64 bit floating point value
value2 the second value to be compared with value1
diff difference to detect value1 != value2
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
-2, if value1 or value2 or both values are invalid (nan)
-1, if value1 is less than value2
0, if value1 is equal with value2
+1, if value1 is greater than value2
double cosinus ( const double  rad,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the cosinus of rad (value in rad)

result = cos( rad )

Parameters:
rad the angle [-numType_MAX .. +numType_MAX]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of [-1 .. +1]
Hint:
the parameter rad will be interpreted in rad (circular measure).
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double cotangent ( const double  rad,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the cotangent of rad

result = cos( rad ) / sin( rad ) = 1 / tan( rad )

Returns:
the result of this operation in double format
The result will be in range of the data type numType
Hint:
rad will be interpreted in rad (circular measure).
rad must be in range of [ -numType_MAX .. +numType_MAX ]
except the values [k*pi (for k element N)]

if sin( rad ) = 0 then the status bit trigonCotErr will also be set
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double deg2Rad ( const double  degree,
BM_STATUS bms = (BM_STATUS*)0 
)

converts degree into radian

rad = (degree / 180) * pi

Parameters:
degree [in] the degree value
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the radian value
int Find ( const __int64 *  element1,
const unsigned int  maxElements,
const __int64  elem 
)

looks for a same element in the array

and returns the zero based index into the array if an equal element is found

Parameters:
element1 pointer to the element in the array where to start
maxElements number of relevant elements in the array beginning at start (element1)
elem the element to be searched for
Returns:
the zero based index of the found element (up from element1).
Return of 0 means that element1[0] fits.
-1 if no element matched
int Find ( const double *  element1,
const unsigned int  maxElements,
const double  elem 
)

looks for a same element in the array

and returns the zero based index into the array if an equal element is found

Parameters:
element1 pointer to the element in the array where to start
maxElements number of relevant elements in the array beginning at start (element1)
elem the element to be searched for
Returns:
the zero based index of the found element (up from element1).
Return of 0 means that element1[0] fits.
-1 if no element matched
double Floor ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

Calculates the floor of value.

Calculates the largest integer that is less than or equal to value

Returns:
the integer value in double format
The result will be in range of the data type numType
Hint:
This method uses the standard C function floor()
Examples:
double value = 2.1;
double result = Floor(value);
printf("\n floor of %f = %f", value, result);
value = -2.9;
result = Floor(value);
printf("\n floor of %f = %f", value, result);
Outputs:
floor of 2.1 = 2.0
floor of -2.9 = -3.0
long getPolyFactors1 ( double *  pf,
const double *  xz 
)

calculates the polynom factors of the given zero condition(s)

solves (x - xz[0]) = 0 -->> pf[0] = -xz[0]

Parameters:
pf [out] result for the polynom factor(s)
pf[0] = offset
xz [in] zero condition(s) for the polynom
Returns:
0 if all is OK
BM_STATUS getPolyFactors2 ( double *  pf,
const double *  xz 
)

calculates the polynom factors of the given zero condition(s)

solves (x - xz[1])*(x - xz[0]) = 0 -->> pf[0,1]

Parameters:
pf [out] result for the polynom factor(s)
pf[0] = offset
pf[1] = x-factor
xz [in] zero condition(s) for the polynom
Returns:
0 if all is OK
BM_STATUS getPolyFactors3 ( double *  pf,
const double *  xz 
)

calculates the polynom factors of the given zero condition(s)

solves (x - xz[2])*(x - xz[1])*(x - xz[0]) = 0 -->> pf[0,1,2]

Parameters:
pf [out] result for the polynom factor(s)
pf[0] = offset
pf[1] = x-factor
pf[2] = x^2-factor
xz [in] zero condition(s) for the polynom
Returns:
0 if all is OK
BM_STATUS getPolyFactors4 ( double *  pf,
const double *  xz 
)

calculates the polynom factors of the given zero condition(s)

solves (x - xz[3])*(x - xz[2])*(x - xz[1])*(x - xz[0]) = 0 -->> pf[0,1,2,3]

Parameters:
pf [out] result for the polynom factor(s)
pf[0] = offset
pf[1] = x-factor
pf[2] = x^2-factor
pf[3] = x^3-factor
xz [in] zero condition(s) for the polynom
Returns:
0 if all is OK
__int64 InvertSign ( const __int64  value,
BM_STATUS bms = (BM_STATUS*)0 
)

inverts the sign of value

result = -value

Returns:
the result of this operation
The result will be in range of the data type numType
See also:
InvertSign(), Positive(), negative()
double InvertSign ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

inverts the sign of value

result = -value

Returns:
the result of this operation in double format
The result will be in range of the data type numType
See also:
InvertSign(), Positive(), negative()
int isEven ( const __int64  value  ) 

returns 1 if value is even (.. -4, -2, 0, +2, +4, ..)

Parameters:
value [in] the value to be checked
Returns:
0 = false : value is odd 1 = true : value is even
bool isValidValue ( const __int64 *  value,
BM_STATUS bms = (BM_STATUS*)0 
)

tests for a valid 64 bit integer (__int64)

Parameters:
value a pointer to value to be tested
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
0 = false, value points not to a valid 64 bit integer
1 = true, value points to a valid 64 bit integer number
in bms (if bms != 0) status bit undef will be set, if value is not valid otherwise bms remains unchanged
Hint:
for 64 bit integer only a null-pointer in value produces an error in bms!
bool isValidValue ( const double *  value,
BM_STATUS bms = (BM_STATUS*)0 
)

tests for a valid 64 bit floating point value (double)

Parameters:
value a pointer to the double value to be tested
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
0 = false, value points not to a valid 64 bit floating point number
1 = true, value points to a valid 64 bit floating point number
in bms (if bms != 0) status bit undef will be set, if value is not valid otherwise bms remains unchanged
Hint:
denormalized values are allowed!
__int64 log_b_x ( const __int64  base,
const __int64  value,
BM_STATUS bms = (BM_STATUS*)0 
)

returns the base-logarithm of value

the log-function solves the equation
base pow result = value
and returns result in double format

Parameters:
base the base of the logarithm (useful >= 2)
value the logarithm's result
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the power to base so that base pow result = value
The result will be in range of [ -DBL_MAX .. +DBL_MAX ]
See also:
doubleRootDouble(), doubleRoot_2(),
doublePowDouble(), logDouble()
double log_b_x ( const double  base,
const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

returns the base-logarithm of value

the log-function solves the equation
base pow result = value
and returns result in double format

Parameters:
base the base of the logarithm (useful >= 2)
value the logarithm's result
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the power to base so that base pow result = value
The result will be in range of [ -DBL_MAX .. +DBL_MAX ]
See also:
doubleRootDouble(), doubleRoot_2(),
doublePowDouble(), logDouble()
__int64 Negative ( const __int64  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the negative absolute value of value

result = - abs( value )

Returns:
the result of this operation
The result will be in negative range of the data type [-numType_MAX .. 0]
See also:
InvertSign(), Positive(), Negative()
double Negative ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the negative absolute value of value

result = -fabs( value )

Returns:
the result of this operation in double format
The result will be in negative range of the data type [-numType_MAX .. 0]
See also:
InvertSign(), Positive(), Negative()
__int64 Positive ( const __int64  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the absolute value of value

result = abs( value )

Returns:
the result of this operation
The result will be in pos. range of the data type [0 .. +numType_MAX]
See also:
InvertSign(), Positive(), Negative()
double Positive ( const double  value,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the absolute value of value

result = fabs( value )

Returns:
the result of this operation in double format
The result will be in pos. range of the data type [0 .. +numType_MAX]
See also:
InvertSign(), Positive(), Negative()
void printBitpattern ( double  value,
FILE *  file = (FILE*)0 
)

prints the bitpattern of a double value in hex format

Parameters:
value the value to be printed
file pointer to a open FILE with write access.
If file=0 (default) this function prints to stdout.
If file is a valid pointer this function prints to file.
Example:
double myFloat = 123.456;
printDoubleBitpattern( myFloat, (FILE*)0 );
Result:
405edd2f1a9fbe77
Illustration:

4 0 5 e d d 2 f 1 a 9 f b e 7 7
Bit 63..0
0100 0000 0101 1110 1101 1101 0010 1111 0001 1010 1001 1111 1011 1110 0111 0111
Bit 51..0: normalized significand
Bit 62..52: exponent
Bit 63: sign
See also:
printDoubleBitpatternFormated()
void printBitpatternFormatted ( double  value,
FILE *  file = (FILE*)0 
)

prints the formatted bitpattern of a double value (sign mantisse exponent)

Parameters:
value the value to be printed
file pointer to a open FILE with write access.
If file=0 (default) this function prints to stdout.
If file is a valid pointer this function prints to file.
Example:
double myFloat = 123.456;
printDoubleBitpatternFormatted( myFloat );
Result:
sign=0 significant=edd2f1a9fbe77 exponent=405
Hint:
All printed values are in hex-format.
See also:
printDoubleBitpattern()
void printBMStatus ( const BM_STATUS  bms,
FILE *  file = (FILE*)0 
)

prints a basic math status (BM_STATUS) to file

Parameters:
bms basic math status to be printed
file pointer to a open FILE with write access.
If file=0 (default) this function prints to stdout.
If file is a valid pointer this function prints to file.
Example:
BM_STATUS bms;
bms.status = 0;
doubleDivDouble( 123.456, 0.0, &bms );
printBM_STATUS( bms, (FILE*)0 );
Result:
status = 0x4 (divideZero )
Comment:
The status text in brackets is sorted from hi-bit (left alligned) to lo-bit
If status is null, the printed text has no brackets. It is only "status = 0x0"
If there are more then 1 bit set, the output looks like "status = 0x82 (negative overflow)"
The status text is the same as the name of the status bit. E.g. if the bit 'undef' is set the status text will be "undef"
double rad2Deg ( const double  radian,
BM_STATUS bms = (BM_STATUS*)0 
)

converts radian into degree

degree = (rad / pi) * 180

Parameters:
radian [in] the radian value
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the degree value
double reciproc_x ( const double  value,
BM_STATUS bms = NULL 
)

safe reciproc (1/x)

returns the result of 1 / x

Parameters:
value [in] the value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of 1 / value
double Round ( const double  value,
const int  decPlaces = 0,
BM_STATUS bms = (BM_STATUS*)0 
)

rounds value to a specified number of decimal places

decPlaces can be negative

Parameters:
value [in] the value to be rounded
decPlaces [in] Positive number indicates how many places to the right of the decimal are included in the rounding.
If omitted (decPlaces=0), assignRound() rounds to integer.
Negative number indicates how many places to the left of the decimal are included in the rounding.
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the result of this operation in double format
The result will be in range of [ -DBL_MAX .. +DBL_MAX ]
Hint:
For negative values this formula will be used to calculate the rounded value:
result = ( value * 10^decPlaces - 0.5 ) / 10^decPlaces
For positive values this formula will be used to calculate the rounded value:
result = ( value * 10^decPlaces + 0.5 ) / 10^decPlaces
double sinus ( const double  rad,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the sinus of rad (value in rad)

result = sin( rad )

Parameters:
rad the angle [-numType_MAX .. +numType_MAX]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of [-1 .. +1]
Hint:
the parameter rad will be interpreted in rad (circular measure).
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
BM_STATUS solveL1 ( double *  xr,
const double *  lf 
)

solves the linear equation with 1 unknown value

equation lf[1] * xr[0] - lf[0] = 0 will be solved for xr[0] = lf[0] / lf[1]

Parameters:
xr [out] the result(s) of the linear equation(s)
lf [in] the linear factors of the equation
Returns:
the number of solutions written to xr
and in xr the result(s) for the unknown variable(s)
BM_STATUS solveL2 ( double *  xr,
double *  lf[2] 
)

solves the linear equations with 2 unknown values

equation 1: lf[0][2] * b + lf[0][1] * a = lf[0][0]
equation 1: lf[1][2] * b + lf[1][1] * a = lf[1][0]
-->> xr[0] = result for a
-->> xr[1] = result for b

Parameters:
xr [out] the result(s) of the linear equation(s)
lf [in] the linear factors of the equation
Returns:
the number of solutions written to xr
and in xr the result(s) for the unknown variable(s)
long solveP1 ( double *  xr,
const double *  pf 
)

solves the polynom function of first degree

solves pf[1]*x + pf[0] = 0 -->> xr[0] = -pf[0] / pf[1]

Parameters:
xr [out] pointer to store the solution(s)
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP1norm ( double *  xr,
const double *  pf 
)

solves the normalized polynom function of first degree

solves x + pf[0] = 0 -->> xr[0] = -pf[0]

Parameters:
xr [out] pointer to store the solution(s)
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP2 ( double *  xr,
const double *  pf 
)

solves the polynom function of second degree

solves pf[2]*x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP2norm ( double *  xr,
const double *  pf 
)

solves the normalized polynom function of second degree

solves x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP3 ( double *  xr,
const double *  pf 
)

solves the polynom function of third degree

solves pf[3]*x^3 + pf[2]*x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1,2]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP3norm ( double *  xr,
const double *  pf 
)

solves the normalized polynom function of third degree

solves x^3 + pf[2]*x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1,2]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP4 ( double *  xr,
const double *  pf 
)

solves the polynom function of fourth degree

solves pf[4]*x^4 + pf[3]*x^3 + pf[2]*x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1,2,3]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
long solveP4norm ( double *  xr,
const double *  pf 
)

solves the normalized polynom function of fourth degree

solves x^4 + pf[3]*x^3 + pf[2]*x^2 + pf[1]*x + pf[0] = 0 -->> xr[0,1,2,3]

Parameters:
xr [out] pointer to store the solution(s)
the solution values are stored in ascendant order
pf [in] polynom factor(s)
Returns:
the number of solutions and the result(s) for x in xr
void sortAscendant ( __int64 *  values,
const unsigned long  count,
BM_STATUS bms = (BM_STATUS*)0 
)

sorts an array of values in ascendant order

Parameters:
values [in,out] the values to be sorted
returns the sorted values in the same array
count [in] number of values in values
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the ascendat sorted values in the same array
void sortAscendant ( double *  values,
const unsigned long  count,
BM_STATUS bms = (BM_STATUS*)0 
)

sorts an array of values in ascendant order

Parameters:
values [in,out] the values to be sorted
returns the sorted values in the same array
count [in] number of values in values
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the ascendat sorted values in the same array
double stringToDbl ( const char *  stringValue,
BM_STATUS bms = (BM_STATUS*)0 
)

converts stringValue into double

Parameters:
stringValue pointer to the first character in the string where the value begins
bms (can be 0) pointer to basic math status (see BM_STATUS) to get error informations
Returns:
the 64 bit floating point value
Hint:
This method uses strtod() to convert the string into a 64 bit float value.
If the string converting failed with errno = ERANGE (overflow),
the status bits strErr and overflow will be set bms.
In case of a negative overflow the status bit negative will also be set.
If there are no valid characters in the string
the status bits strErr and undef will be set in bms.
__int64 stringToInt64 ( const char *  stringValue,
char **  stopChar = (char**)0,
BM_STATUS bms = (BM_STATUS*)0 
)

converts stringValue into __int64

Parameters:
stringValue pointer to the first character in the string where the value begins
stopChar [out,opt] (can be null) pointer into stringValue where the scanner stopped
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the 64 bit integer value
Hint:
If the string converting failed because of overflow
the status bits strErr and/or overflow will be set in bms.
In case of a negative overflow the status bit negative will also be set.
If there are no valid characters in the string
the status bits strErr and undef will be set in bms.
double strToDbl ( const char *  str,
BM_STATUS bms = NULL 
)

converts a null terminated string into a 80 bit floating point value (double)

returns the value represented by the string

Parameters:
str [in] the zero terminated string
fpvalue ::= {whitespace}[sign]value[echar[sign]integer]
whitespace ::= ' ' | '\t' | '\n' | '\r' //blank or tabulator or linefeed or carriage return
sign ::= '+' | '-' //plus or minus
seperator ::= ',' | '_' //comma or underline
digit ::= '0' ... '9' //a value in the range 0..9
integer ::= digit {digit} //integer has at least one digit
int_sep ::= digit {[seperator]digit} //integer begins and ends always
//with a digit, not with a seperator
value ::= (integer) | (integer'.') | (integer'.'integer) | ('.'integer)
echar ::= 'd' | 'D' | 'e' | 'E' //one of these characters indicates the
//power to base 10
bms [out,opt] basic math status
pointer to receive status information
bms remains unchanged, if there is no error in this function
(bms acts accumulative)
Returns:
the value represented by the string
double tangent ( const double  rad,
BM_STATUS bms = (BM_STATUS*)0 
)

calculates the tangent of rad

result = tan( rad )

Parameters:
rad the angle [-numType_MAX .. +numType_MAX]
bms pointer to basic math status to receive error informations
Returns:
the result of this operation in double format
The result will be in range of the data type numType
Hint:
value will be interpreted in rad (circular measure).
value must be in range of [ -numType_MAX .. +numType_MAX ]
except the values [k*PI/2 (for k element N and k != 0)]

With 64 bits, pi/2 is not so exact that tan( pi/2 ) will overflow.
In other words: Don't worry about the poles within the tan-function.
See also:
sinus(), cosinus(), tangent(), cotangent()
arcSin(), arcCos(), arcTan(), arcCot()
rad2Deg(), deg2Rad()
double toDouble ( const __int64  value  ) 

converts value to a value in double format

Parameters:
value [in] the value which will be converted to double
Returns:
value in double format (64 bit floating point)
__int64 toInt64 ( const double  value,
double *  intDbl = (double*)0,
BM_STATUS bms = (BM_STATUS*)0 
)

strips the decimal places from value and returns the integer (__int64)

Extracts the integer part from value

Returns:
the integer part of value in range of [LLONG_MIN .. LLONG_MAX] (__int64)
in intDbl the integer part of value in double format
The result will be in range of the data type numType
Hint:
for positive values this method uses floor()
and for negative values the method ceil() is used

The status bit int64overflow will be set, if value is out of range [LLONG_MIN..LLONG_MAX].
In case of value < LLONG_MIN the status bit negative will also be set.
Notice:
Also in case of int64overflow, intDbl always represents the mathematical correct integer value!!!
In other words: intDbl will not be limitted to an integer range.
int64overflow is a usefull information before casting value into a int64 variable.
Example:
double value = -numType_MAX;
double intDbl = 0.0;
double expected = -numType_MAX; //expected result
BM_STATUS bms;
bms.status = 0;
__int64 result = doubleToInt64( value, &intDbl, &bms );
printBM_STATUS( bms, 0 );
Output
status = 0x80001000 (negative int64overflow )
__int64 x_add_y ( const __int64  augend,
const __int64  addend,
BM_STATUS bms = NULL 
)

safe addition

adds addend to augend and returns the result of this operation

Parameters:
augend [in] the first value for this operation
addend [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of augend + addend (add)
double x_add_y ( const double  augend,
const double  addend,
BM_STATUS bms = NULL 
)

safe addition

adds addend to augend and returns the result of this operation

Parameters:
augend [in] the first value for this operation
addend [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of augend + addend (add)
__int64 x_div_y ( const __int64  numerator,
const __int64  denominator,
BM_STATUS bms = NULL 
)

safe division

divides numerator with denominator and returns the result of this operation

Parameters:
numerator [in] the first value for this operation
denominator [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of numerator / denominator (div)
double x_div_y ( const double  numerator,
const double  denominator,
BM_STATUS bms = NULL 
)

safe division

divides numerator with denominator and returns the result of this operation

Parameters:
numerator [in] the first value for this operation
denominator [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of numerator / denominator (div)
__int64 x_mod_y ( const __int64  numerator,
const __int64  denominator,
BM_STATUS bms = NULL 
)

safe modulo

divides numerator with denominator and returns the remainder as result of this operation

Parameters:
numerator [in] the first value for this operation
denominator [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of numerator % denominator (mod)
double x_mod_y ( const double  numerator,
const double  denominator,
BM_STATUS bms = NULL 
)

safe modulo

divides numerator with denominator and returns the remainder as result of this operation

Parameters:
numerator [in] the first value for this operation
denominator [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of numerator % denominator (mod)
__int64 x_mul_y ( const __int64  multiplier,
const __int64  multiplicand,
BM_STATUS bms = NULL 
)

safe multiplication

multiplies multiplier with multiplicand and returns the result of this operation

Parameters:
multiplier [in] the first value for this operation
multiplicand [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of multiplier * multiplicand (mul)
double x_mul_y ( const double  multiplier,
const double  multiplicand,
BM_STATUS bms = NULL 
)

safe multiplication

multiplies multiplier with multiplicand and returns the result of this operation

Parameters:
multiplier [in] the first value for this operation
multiplicand [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of multiplier * multiplicand (mul)
__int64 x_pow_2 ( const __int64  base,
BM_STATUS bms = NULL 
)

safe square (power 2)

calculates base raised to the power of 2 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 2 (pow)
double x_pow_2 ( const double  base,
BM_STATUS bms = NULL 
)

safe square (power 2)

calculates base raised to the power of 2 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 2 (pow)
__int64 x_pow_3 ( const __int64  base,
BM_STATUS bms = NULL 
)

safe cube (power 3)

calculates base raised to the power of 3 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 3 (pow)
double x_pow_3 ( const double  base,
BM_STATUS bms = NULL 
)

safe cube (power 3)

calculates base raised to the power of 3 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 3 (pow)
__int64 x_pow_4 ( const __int64  base,
BM_STATUS bms = NULL 
)

safe power 4

calculates base raised to the power of 4 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 4 (pow)
double x_pow_4 ( const double  base,
BM_STATUS bms = NULL 
)

safe power 4

calculates base raised to the power of 4 and returns the result of this operation

Parameters:
base [in] the base value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ 4 (pow)
__int64 x_pow_y ( const __int64  base,
const __int64  exponent,
BM_STATUS bms = (BM_STATUS*)0 
)

safe power, calculates base pow exponent

calculates base raised to the power of exponent and returns the result of this operation

Parameters:
base [in] the base value for this operation
exponent [in] the exponent value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ exponent (pow)
The result will be in range of the data type numType
See also:
doubleRootDouble(), sqrtDouble(), logDouble()
double x_pow_y ( const double  base,
const double  exponent,
BM_STATUS bms = (BM_STATUS*)0 
)

safe power, calculates base pow exponent

calculates base raised to the power of exponent and returns the result of this operation

Parameters:
base [in] the base value for this operation
exponent [in] the exponent value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of base ^ exponent (pow)
The result will be in range of the data type numType
See also:
doubleRootDouble(), sqrtDouble(), logDouble()
__int64 x_root_2 ( const __int64  radicand,
BM_STATUS bms = (BM_STATUS*)0 
)

safe square root

calculates the square root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
if radicand >= 0 : sqrt( radicand )
if radicand < 0 : -sqrt( fabs( radicand ) ) and bms->negRadicand will be set
double x_root_2 ( const double  radicand,
BM_STATUS bms = (BM_STATUS*)0 
)

safe square root

calculates the square root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
bms [out,opt] a pointer to store error informations like overflow
status remains unchanged, if there is no error in this calculation
(status acts accumulative)
Returns:
if radicand => 0 : sqrt( radicand )
if radicand < 0 : -sqrt( fabs( radicand ) ) and bms->negRadicand will be set
double x_root_3 ( const double  radicand,
BM_STATUS bms = (BM_STATUS*)0 
)

safe cube root

calculates the cube root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of root3( radicand )
double x_root_4 ( const double  radicand,
BM_STATUS bms = (BM_STATUS*)0 
)

safe 4th root

calculates the 4th root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of root4( radicand )
__int64 x_root_y ( const __int64  radicand,
const __int64  rootExponent,
BM_STATUS bms = (BM_STATUS*)0 
)

safe exp-th root

calculates the exp-th root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
rootExponent [in] the exponent of the root
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of root-exp( radicand )
double x_root_y ( const double  radicand,
const double  rootExponent,
BM_STATUS bms = (BM_STATUS*)0 
)

safe exp-th root

calculates the exp-th root of radicand and returns the result of this operation

Parameters:
radicand [in] the value for this operation
rootExponent [in] the exponent of the root
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of root-exp( radicand )
__int64 x_sub_y ( const __int64  minuend,
const __int64  subtrahend,
BM_STATUS bms = NULL 
)

safe subtraction

subtracts subtrahend from minuend and returns the result of this operation

Parameters:
minuend [in] the first value for this operation
subtrahend [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of minuend - subtrahend (sub)
double x_sub_y ( const double  minuend,
const double  subtrahend,
BM_STATUS bms = NULL 
)

safe subtraction

subtracts subtrahend from minuend and returns the result of this operation

Parameters:
minuend [in] the first value for this operation
subtrahend [in] the second value for this operation
bms [out,opt] basic math status
a pointer to store error informations like overflow
bms remains unchanged, if there is no error in this calculation
(bms acts accumulative)
Returns:
the result of minuend - subtrahend (sub)
 All Classes Files Functions Variables Typedefs Defines
Generated on Mon Nov 22 06:27:34 2010 by  doxygen 1.6.3