![]() |
Imt.Base C++ API V4.1.1.0
|
Mathematical utility functions. More...
#include <Imt.Base.Core.Math/inc/Imt.Base.Core.Math/Maths.h>
Static Public Member Functions | |
template<typename Type > | |
static bool | areEqualNumbers (Type const left, Type const right) |
Compares two numbers. | |
template<typename Type > | |
static bool | areEqualFloats (Type const left, Type const right) |
Compares two floating point numbers. | |
template<typename Type > | |
static bool | areEqualArrayFloats (Type const *left, Type const *right, size_t size) |
Compares two floating point arrays. | |
template<typename Type > | |
static Type | sqrt (Type const sqVal) |
Find square root of a value. | |
template<typename Type > | |
static Type | nsqrt (Type const sqVal, Type n) |
Find n-th root of a value. | |
template<typename Type > | |
static Type | nsqrt (Type const sqVal, int32_t n) |
template<typename Type > | |
static Type | exp (Type const value) |
Computes e (Euler's number, 2.7182818...) raised to the given power arg. | |
template<typename Type > | |
static Type | ln (Type const arg) |
Computes the natural (base e) logarithm of arg. | |
template<typename Type > | |
static Type | log10 (Type const arg) |
Computes the common (base-10) logarithm of n. | |
template<typename Type > | |
static Type | pow (Type const base, int32_t const exp) |
Computes the value of base (m) raised to the power exponent (n) | |
static float64_t | pow10 (int32_t const exp) |
Computes the value of 10 raised to the power exp. | |
template<typename Type > | |
static Type | fabs (Type const value) |
Find absolute value of a given input. | |
template<typename Type > | |
static Type | abs (Type const value) |
Find absolute value of a given input. | |
template<typename Type > | |
static Type | sin (Type const value) |
Computes the sine of arg (measured in radians) | |
template<typename Type > | |
static Type | cos (Type const value) |
Computes the cosine of arg (measured in radians) | |
template<typename Type > | |
static Type | tan (Type const value) |
Computes the tangens of arg (measured in radians) | |
template<typename Type > | |
static Type | arcos (Type const value) |
Computes the arccos of arg. | |
template<typename Type > | |
static Type | arsin (Type const value) |
Computes the arsin of arg. | |
template<typename Type > | |
static Type | artan (Type const value) |
Computes the arctan of arg. | |
template<typename Type > | |
static Type | artan2 (Type const y, Type const x) |
Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant. | |
template<typename Type > | |
static Type | cosh (Type const value) |
Computes the cosh of arg (measured in radians) | |
template<typename Type > | |
static Type | sinh (Type const value) |
Computes the sinh of arg (measured in radians) | |
template<typename Type > | |
static Type | tanh (Type const value) |
Computes the tanh of arg (measured in radians) | |
template<typename Type > | |
static Type | arsinh (Type const value) |
Computes the arsinh of arg (measured in radians) | |
template<typename Type > | |
static Type | arcosh (Type const value) |
Computes the acosh of arg (measured in radians) | |
template<typename Type > | |
static Type | artanh (Type const value) |
Computes the inverse hyperbolic tangent of arg. | |
template<typename Type > | |
static Type | copysign (Type const &x, Type const &y) |
Returns a value with the magnitude of x and the sign of y. | |
template<typename Type > | |
static Type | erf (Type const &x) |
Compute error function. | |
template<typename Type > | |
static Type | erfc (Type const &x) |
Compute complementary error function. | |
template<typename Type > | |
static Type | expm1 (Type const &x) |
Compute exponential minus one. | |
template<typename Type > | |
static Type | fdim (Type const &x, Type const &y) |
Positive difference. | |
template<typename Type > | |
static Type | floor (Type const &x) |
Round down value. | |
template<typename Type > | |
static Type | fmod (Type const &numer, Type const &denom) |
Compute remainder of division. | |
template<typename Type > | |
static Type | frexp (Type const &x, int32_t *exp) |
Get significand and exponent. | |
template<typename Type > | |
static Type | hypot (Type const &x, Type const &y) |
Compute hypotenuse. | |
template<typename Type > | |
static int32_t | ilogb (Type const &x) |
Integer binary logarithm. | |
template<typename Type > | |
static bool | isinf (Type const &x) |
Is infinity. | |
template<typename Type > | |
static bool | isnan (Type const &x) |
Is Not-A-Number. | |
static double | nan (char const *tagp) |
Generate quiet NaN. | |
static float | nanf (char const *tagp) |
Generate quiet NaN. | |
template<typename Type > | |
static bool | ldexp (Type const &x, int32_t exp) |
Generate value from significand and exponent. | |
template<typename Type > | |
static Type | log1p (Type const &x) |
Compute logarithm plus one. | |
template<typename Type > | |
static Type | log2 (Type const &x) |
Compute binary logarithm. | |
template<typename Type > | |
static Type | logb (Type const &x) |
Compute floating-point base logarithm. | |
template<typename Type > | |
static Type | modf (Type const &x, Type *intpart) |
Break into fractional and integral parts. | |
template<typename Type > | |
static Type | modf (Type const &x, int8_t const *tagp) |
Generate quiet NaN. | |
template<typename Type > | |
static Type | nextafter (Type const &x, Type const &y) |
Next representable value. | |
template<typename Type > | |
static Type | remainder (Type const &numer, Type const &denom) |
Compute remainder (IEC 60559) | |
template<typename Type > | |
static Type | remquo (Type const &numer, Type const &denom, int32_t *quot) |
Compute remainder and quotient. | |
template<typename Type > | |
static Type | rint (Type const &x) |
Round to integral value. | |
template<typename Type > | |
static Type | scalbln (Type const &x, long int n) |
Scale significand using floating-point base exponent (long) | |
template<typename Type > | |
static Type | scalbn (Type const &x, int32_t n) |
Scale significand using floating-point base exponent. | |
template<typename Type > | |
static Type | trunc (Type const &x) |
Truncate value. | |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Compute exponential minus one.
Returns e raised to the power x minus one: ex-1. For small magnitude values of x, expm1 may be more accurate than exp(x)-1.
x | Value of the exponent. |
|
inlinestatic |
|
inlinestatic |
Positive difference.
Returns the positive difference between x and y. The function returns x-y if x>y, and zero otherwise.
x | Values whose difference is calculated. |
y | Values whose difference is calculated. |
|
inlinestatic |
|
inlinestatic |
Compute remainder of division.
Returns the floating-point remainder of numer/denom (rounded towards zero):
fmod = numer - tquot * denom
numer | Value of the quotient numerator. |
denom | Value of the quotient denominator. |
|
inlinestatic |
Get significand and exponent.
Breaks the floating point number x into its binary significand (a floating point with an absolute value between 0.5(included) and 1.0(excluded)) and an integral exponent for 2, such that:
x = significand * 2 exponent The exponent is stored in the location pointed by exp, and the significand is the value returned by the function.
If x is zero, both parts (significand and exponent) are zero. If x is negative, the significand returned by this function is negative.
x | Value to be decomposed. |
exp | Pointer to an int where the value of the exponent is stored. |
|
inlinestatic |
Compute hypotenuse.
Returns the hypotenuse of a right-angled triangle whose legs are x and y.
The function returns what would be the square root of the sum of the squares of x and y (as per the Pythagorean theorem), but without incurring in undue overflow or underflow of intermediate values.
x | Floating point values corresponding to the legs of a right-angled triangle for which the hypotenuse is computed. |
y | Floating point values corresponding to the legs of a right-angled triangle for which the hypotenuse is computed. |
|
inlinestatic |
Integer binary logarithm.
Returns the integral part of the logarithm of |x|, using FLT_RADIX as base for the logarithm.
This is the exponent used internally by the machine to express the floating-point value x, when it uses a significand between 1.0 and FLT_RADIX, so that, for a positive x:
x = significand * FLT_RADIX exponent
Generally, FLT_RADIX is 2, and the value returned by this function is one less than the exponent obtained with frexp (because of the different significand normalization as [1.0,2.0) instead of [0.5,1.0)).
x | Value whose ilogb is returned. |
|
inlinestatic |
|
inlinestatic |
Is Not-A-Number.
Returns whether x is a NaN (Not-A-Number) value.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
x | A floating-point value. |
|
inlinestatic |
Generate value from significand and exponent.
Returns the result of multiplying x (the significand) by 2 raised to the power of exp (the exponent).
lexpr(x,exp) = x * 2 exp
x | Floating point value representing the significand. |
exp | Value of the exponent. |
x * 2 exp
If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL (or HUGE_VALF or HUGE_VALL) with the proper sign.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Compute floating-point base logarithm.
Returns the logarithm of |x|, using FLT_RADIX as base for the logarithm.
On most platforms, FLT_RADIX is 2, and thus this function is equivalent to log2 for positive values.
x | Value whose logarithm is calculated. |
|
inlinestatic |
Generate quiet NaN.
Returns a quiet NaN (Not-A-Number) value of type double.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
The argument can be used by library implementations to distinguish different NaN values in a implementation-specific manner.
Similarly, nanf and nanl return NaN values of type float and long double, respectively.
x | Floating point value to break into parts. |
tagp | An implementation-specific C-string. If this is an empty string (""), the function returns a generic NaN value (the same as returned by passing "NAN" to strtod). |
|
inlinestatic |
Break into fractional and integral parts.
Breaks x into an integral and a fractional part.
The integer part is stored in the object pointed by intpart, and the fractional part is returned by the function. Both parts have the same sign as x.
x | Floating point value to break into parts. |
intpart | Pointer to an object (of the same type as x) where the integral part is stored with the same sign as x. |
|
inlinestatic |
Generate quiet NaN.
Returns a quiet NaN (Not-A-Number) value of type double.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
The argument can be used by library implementations to distinguish different NaN values in a implementation-specific manner.
Similarly, nanf and nanl return NaN values of type float and long double, respectively.
tagp | An implementation-specific C-string. If this is an empty string (""), the function returns a generic NaN value (the same as returned by passing "NAN" to strtod). |
|
inlinestatic |
Generate quiet NaN.
Returns a quiet NaN (Not-A-Number) value of type float.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
The argument can be used by library implementations to distinguish different NaN values in a implementation-specific manner.
Similarly, nanf and nanl return NaN values of type float and long float, respectively.
tagp | An implementation-specific C-string. If this is an empty string (""), the function returns a generic NaN value (the same as returned by passing "NAN" to strtod). |
|
inlinestatic |
Next representable value.
Returns the next representable value after x in the direction of y.
The similar function, nexttoward has the same behavior, but it takes a long double as second argument.
If both parameters compare equal, the function returns y.
x | Base value |
y | Value toward which the return value is approximated. |
|
inlinestatic |
|
inlinestatic |
Find n-th root of a value.
sqVal | The value to which square root has to be calculated. |
n | The root type |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinestatic |
|
inlinestatic |
Compute remainder (IEC 60559)
Returns the floating-point remainder of numer/denom (rounded to nearest):
remainder = numer - rquot * denom
Where rquot is the result of: numer/denom, rounded toward the nearest integral value (with halfway cases rounded toward the even number).
numer | Value of the quotient numerator. |
denom | Value of the quotient denominator. |
|
inlinestatic |
Compute remainder and quotient.
Returns the same as remainder, but it additionally stores the quotient internally used to determine its result in the object pointed by quot.
The value pointed by quot contains the congruent modulo with at least 3 bits of the integral quotient numer/denom.
numer | Value of the quotient numerator. |
denom | Value of the quotient denominator. |
quot | Pointer to an object where the quotient internally used to determine the remainder is stored as a value of type int. |
|
inlinestatic |
Round to integral value.
Rounds x to an integral value, using the rounding direction specified by fegetround.
This function may raise an FE_INEXACT exception if the value returned differs in value from x. See nearbyint for an equivalent function that cannot raise such exception.
x | Value to round. |
|
inlinestatic |
Scale significand using floating-point base exponent (long)
Scales x by FLT_RADIX raised to the power of n, returning the result of computing:
scalbn(x,n) = x * FLT_RADIXn
Presumably, x and n are the components of a floating-point number in the system; In such a case, this function may be optimized to be more efficient than the theoretical operations to compute the value explicitly.
There also exists another version of this function: scalbn, which is identical, except that it takes an int as second argument.
x | floating point value |
n | integer value |
|
inlinestatic |
Scale significand using floating-point base exponent.
Scales x by FLT_RADIX raised to the power of n, returning the same as::
scalbn(x,n) = x * FLT_RADIXn
Presumably, x and n are the components of a floating-point number in the system; In such a case, this function may be optimized to be more efficient than the theoretical operations to compute the value explicitly.
On most platforms, FLT_RADIX is 2, making this function equivalent to ldexp.
x | Value representing the significand. |
n | Value of the exponent. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |