Math.h

Classes

Global Functions -- AIPS++ interface to math.h and other scalar math functions (full description)

AIPS++ interface to math.h and other scalar math functions (source)

Interface

inline Float pow(Float f1, Double f2)
inline Float pow(Double f1, Float f2)
inline Int pow(Int f1, Int f2)
inline Int ifloor(Float point)
inline Int ifloor(Double point)
inline Int max(Int a, Int b)
inline Int min(Int a, Int b)
inline uInt max(uInt a, uInt b)
inline uInt min(uInt a, uInt b)
inline Double max(Double a, Double b)
inline Double min(Double a, Double b)
inline Double max(Double a, Float b)
inline Double min(Double a, Float b)
inline Double max(Float a, Double b)
inline Double min(Float a, Double b)
inline Float max(Float a, Float b)
inline Float min(Float a, Float b)
inline uInt abs(uInt Val)
inline Int square(Int val)
inline Float square(Float val)
inline Double square(Double val)
inline Int cube(Int val)
inline Float cube(Float val)
inline Double cube(Double val)
Bool near(uInt val1, uInt val2, Double tol = 1.0e-5)
Bool near(Int val1, Int val2, Double tol = 1.0e-5)
Bool near(Float val1, Float val2, Double tol = 1.0e-5)
Bool near(Float val1, Double val2, Double tol = 1.0e-5)
Bool near(Double val1, Float val2, Double tol = 1.0e-5)
Bool near(Double val1, Double val2, Double tol = 1.0e-13)
inline Bool allNear(uInt val1, uInt val2, Double tol = 1.0e-5)
inline Bool allNear(Int val1, Int val2, Double tol = 1.0e-5)
inline Bool allNear(Float val1, Double val2, Double tol = 1.0e-5)
inline Bool allNear(Double val1, Float val2, Double tol = 1.0e-5)
inline Bool allNear(Float val1, Float val2, Double tol = 1.0e-5)
inline Bool allNear(Double val1, Double val2, Double tol = 1.0e-13)
Bool nearAbs(uInt val1, uInt val2, Double tol = 1.0e-5)
Bool nearAbs(Int val1, Int val2, Double tol = 1.0e-5)
Bool nearAbs(Float val1, Float val2, Double tol = 1.0e-5)
Bool nearAbs(Float val1, Double val2, Double tol = 1.0e-5)
Bool nearAbs(Double val1, Float val2, Double tol = 1.0e-5)
Bool nearAbs(Double val1, Double val2, Double tol = 1.0e-13)
inline Bool allNearAbs(uInt val1, uInt val2, uInt tol = 1)
inline Bool allNearAbs(Int val1, Int val2, Int tol = 1)
inline Bool allNearAbs(Float val1, Float val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Float val1, Double val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Double val1, Float val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Double val1, Double val2, Double tol = 1.0e-13)
inline Bool isFinite (const Float& val)
inline Bool isFinite (const Double& val)
inline Bool isNaN (const Float& val)
inline Bool isNaN(Double val)
Float floatNaN()
Double doubleNaN()
void setNaN(Float& val)
void setNaN(Double& val)
Bool isInf(Float val)
Bool isInf(Double val)
Float floatInf()
Double doubleInf()
void setInf(Float& val)
void setInf(Double& val)

Description

Synopsis

AIPS++ interface to <math.h>. You should include this file rather than <math.h> directly. It will be used to cover up any deficiencies in the system <math.h>.

This file does not include things like element-by-element array operations. See the ArrayMath functions for these functions.

This file includes the standard math library. Hence besides the functions defined here the following functions are also available.

    Double sin(Double x)       Sine function
    Double cos(Double x)       Cosine function
    Double tan(Double x)       Tangent function
    Double asin(Double x)      Inverse sine function
    Double acos(Double x)      Inverse cosine function
    Double atan(Double x)      Inverse tangent function
    Double atan2(Double y, Double x) Four quandrant inverse tangent function
    Double hypot(Double y, Double x) Euclidean distance sqrt(x*x+y*y)
    
    Double sinh(Double x)      Hyperbolic sine
    Double cosh(Double x)      Hyperbolic cosine
    Double tanh(Double x)      Hyperbolic tangent
    Double acosh(Double x)     Inverse hyperbolic sine
    Double asinh(Double x)     Inverse hyperbolic cosine
    Double atanh(Double x)     Inverse hyperbolic tangent
    
    Double sqrt(Double x)      Square root
    Double cbrt(Double x)      Cube root
    
    Double pow(Double x, Double y) x raised to the power of y
    Double exp(Double x)       Exponental function
    Double expm1(Double x)     exp(x)-1. Use when x is small.
    Double log(Double x)       Natural logarithm
    Double log10(Double x)     Base ten logarithm
    Double log1p(Double x)     log(x+1). Use when x is small
    
    Double j0(Double x)        Bessel function of the first kind, zeroth order 
    Double j1(Double x)        Bessel function of the first kind, first order
    Double jn(Int n, Double x) Bessel function of the first kind nth order
    Double y0(Double x)        Bessel function of the second kind, zeroth order 
    Double y1(Double x)        Bessel function of the second kind, first order 
    Double yn(Int n, Double x) Bessel function of the second kind, nth order
    
    Double lgamma(Double x)    Natural Log of the absolute value of the gamma
                               function
    Double lgamma_r(Double x, Int* sign) Same as lgamma. The sign of the gamma
                               function is returned in the second argument.
    
    Double erf(Double x)       Error function
    Double erfc(Double x)      Complementary error function (1 - erf(x)). 
                               Use for large x.
    
    Double ceil(Double x)      Returns the least integral value greater than or
                               equal to x
    Double floor(Double x)     Returns the least integral value than than or
                               equal to x
    Double rint(Double x)      Round to an integer using the current direction.
    
    Double fabs(Double x)      Absolute value of x
    Double remainder(Double x, Double y) the remainder. x - y*Int(x/y)
    Double fmod(Double x, Double y) As above. May differ by +/- y
    Int isNaN(Double x) Returns 1 if x is a NaN, zero otherwise
    Int ilogb(Double x) Unbiased exponent of x
    Double logb(Double x)      As above but returns floating point result
    Double scalbn(Double x, Int n) x*2**n. Uses exponent manipulation.
    Double scalb(Double x, Double n) x*2**n. As above but n is a Double
    Double significand(Double x) Returns the fractional part of x 
                               (between 1 and 2)
    Double copysign(Double x, Double y)  returns a value with the magnitude of
                                         x and the sign bit of y.
    Double nextafter(Double x, Double y) Returns the next machine representable
                               number after x in the direction specified by y
    

This file also includes the standard C library (stdlib.h). This is to obtain a definition of the following functions.

 Int abs(Int x)             absolute value function
 </synopsis>

 

Member Description

inline Float pow(Float f1, Double f2)
inline Float pow(Double f1, Float f2)
inline Int pow(Int f1, Int f2)

Returns f1**f2. The Double precision version is defined in the standard library. But many compilers are not good enough to automatically do the type promotion. Hence these functions are explicitly defined.

inline Int ifloor(Float point)
inline Int ifloor(Double point)

Return the integer "less than" point (i.e. the one further from zero if "point" is negative.

inline Int max(Int a, Int b)
inline Int min(Int a, Int b)
inline uInt max(uInt a, uInt b)
inline uInt min(uInt a, uInt b)
inline Double max(Double a, Double b)
inline Double min(Double a, Double b)
inline Double max(Double a, Float b)
inline Double min(Double a, Float b)
inline Double max(Float a, Double b)
inline Double min(Float a, Double b)
inline Float max(Float a, Float b)
inline Float min(Float a, Float b)

Functions to get the max or min of two numbers.

inline uInt abs(uInt Val)

Get the absolute value of uInt. Should already be defined for integers in <stdlib.h>. Define it for uInts so that certain compilers can resolve the ambiguity when used in a templated class.

inline Int square(Int val)
inline Float square(Float val)
inline Double square(Double val)

Return the square of a value.

inline Int cube(Int val)
inline Float cube(Float val)
inline Double cube(Double val)

Return the cube of a value.

Bool near(uInt val1, uInt val2, Double tol = 1.0e-5)
Bool near(Int val1, Int val2, Double tol = 1.0e-5)
Bool near(Float val1, Float val2, Double tol = 1.0e-5)
Bool near(Float val1, Double val2, Double tol = 1.0e-5)
Bool near(Double val1, Float val2, Double tol = 1.0e-5)
Bool near(Double val1, Double val2, Double tol = 1.0e-13)

Functions to return whether a value is "relatively" near another. Returns tol > abs(val2 - val1)/max(abs(val1),(val2)). If tol <= 0, returns val1 == val2. If either val is 0.0, take care of area around the minimum number that can be represented.

inline Bool allNear(uInt val1, uInt val2, Double tol = 1.0e-5)
inline Bool allNear(Int val1, Int val2, Double tol = 1.0e-5)
inline Bool allNear(Float val1, Double val2, Double tol = 1.0e-5)
inline Bool allNear(Double val1, Float val2, Double tol = 1.0e-5)
inline Bool allNear(Float val1, Float val2, Double tol = 1.0e-5)
inline Bool allNear(Double val1, Double val2, Double tol = 1.0e-13)

The "allNear" versions are aliases for the normal "near" versions. They exist to make template functions that work for both arrays and scalars easier to write. These functions should be moved to ArrayMath.h

Bool nearAbs(uInt val1, uInt val2, Double tol = 1.0e-5)
Bool nearAbs(Int val1, Int val2, Double tol = 1.0e-5)
Bool nearAbs(Float val1, Float val2, Double tol = 1.0e-5)
Bool nearAbs(Float val1, Double val2, Double tol = 1.0e-5)
Bool nearAbs(Double val1, Float val2, Double tol = 1.0e-5)
Bool nearAbs(Double val1, Double val2, Double tol = 1.0e-13)

Functions to return whether a value is "absolutely" near another. Returns tol > abs(val2 - val1)

inline Bool allNearAbs(uInt val1, uInt val2, uInt tol = 1)
inline Bool allNearAbs(Int val1, Int val2, Int tol = 1)
inline Bool allNearAbs(Float val1, Float val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Float val1, Double val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Double val1, Float val2, Double tol = 1.0e-5)
inline Bool allNearAbs(Double val1, Double val2, Double tol = 1.0e-13)

The "allNearAbs" versions are aliases for the normal "nearAbs" versions. They exist to make template functions that work for both arrays and scalars easier to write. These functions should be in ArrayMath.h

inline Bool isFinite (const Float& val)
inline Bool isFinite (const Double& val)

Functions to test if a floating point number is finite. It is if it is NaN nor infinity.

inline Bool isNaN (const Float& val)
inline Bool isNaN(Double val)

Functions to test for IEEE NaN's. The Float variant uses an in-line Macro examining the bit pattern (for portability and efficiency). The Double version invokes the IEEE function isnan found in ieeefp.h or math.h

Float floatNaN()
Double doubleNaN()
void setNaN(Float& val)
void setNaN(Double& val)

Functions that return IEEE NaN's. The specific NaN returned has all bits set. This is 'quiet' NaN, and because the sign bit is set it may be considered a negative number (but NaN's are not numbers!).

Bool isInf(Float val)
Bool isInf(Double val)

Functions to test for IEEE Infinity's. Should work for positive or negative infinity.

Float floatInf()
Double doubleInf()
void setInf(Float& val)
void setInf(Double& val)

Functions that return an IEEE Infinity, (positive infinity).