Math wrappers. More...
#include <kanzi/core/cpp/platform.hpp>
#include <kanzi/core/legacy/kzs_types.hpp>
#include <kanzi/core/legacy/debug/kzs_error.hpp>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
Classes | |
union | KZ_FLOAT_UNION_TYPE |
Used for keeping strict aliasing when interpreting kzU32 as kzFloat. More... | |
Macros | |
#define | KZS_PI |
Mathematical constant pi. More... | |
#define | KZS_E |
Mathematical constant e. More... | |
#define | KZS_LN_2 |
Natural logarithm of 2. More... | |
#define | KZ_FLOAT_MAXIMUM |
Largest value for a floating point number. More... | |
#define | KZ_FLOAT_MINIMUM |
Most negative value for a floating point number. More... | |
#define | KZ_FLOAT_SMALLEST_POSITIVE |
Smallest normalized value larger than positive zero. More... | |
#define | KZ_FLOAT_EPSILON |
Smallest float such that 1.0f + KZ_FLOAT_EPSILON != 1.0f. More... | |
#define | KZ_INT_MAXIMUM |
Largest value for integer. More... | |
#define | KZ_INT_MINIMUM |
Smallest value for integer. More... | |
#define | KZ_UINT_MAXIMUM |
Largest value for unsigned integer. More... | |
#define | KZ_UINT32_MAXIMUM |
Largest value for 32-bit unsigned integer. More... | |
#define | KZS_NAN |
Floating point value for Not a Number. More... | |
#define | KZS_INFINITY |
Floating point value for positive infinity. More... | |
Functions | |
KZ_INLINE kzBool | kzsIsNan (kzFloat x) |
Returns KZ_TRUE if x is NaN. More... | |
KZ_INLINE kzBool | kzsIsPositiveInfinity (kzFloat x) |
Returns KZ_TRUE if x is positive infinity. More... | |
KZ_INLINE kzBool | kzsIsNegativeInfinity (kzFloat x) |
Returns KZ_TRUE if x is negative infinity. More... | |
KZ_INLINE kzBool | kzsIsInfinity (kzFloat x) |
Returns KZ_TRUE if x is an infinity. More... | |
KZ_INLINE kzBool | kzsIsIEEEPositiveInfinity (kzFloat x) |
Returns KZ_TRUE if x is the specific IEEE floating point positive infinity constant. More... | |
KZ_INLINE kzFloat | kzsSinf (kzFloat angleInRadians) |
Returns sine of given angle. More... | |
KZ_INLINE kzFloat | kzsCosf (kzFloat angleInRadians) |
Returns cosine of given angle. More... | |
KZ_INLINE kzFloat | kzsAsinf (kzFloat x) |
Returns inverse sine from floating point number between -1 and 1. More... | |
KZ_INLINE kzFloat | kzsAcosf (kzFloat x) |
Returns inverse cosine from floating point number between -1 and 1. More... | |
KZ_INLINE kzFloat | kzsTanf (kzFloat angleInRadians) |
Returns tangent of given angle. More... | |
KZ_INLINE kzFloat | kzsAtanf (kzFloat x) |
Returns atan from floating point number. More... | |
KZ_INLINE kzFloat | kzsAtan2f (kzFloat y, kzFloat x) |
Returns atan2 from floating point number. More... | |
KZ_INLINE kzFloat | kzsSqrtf (kzFloat value) |
Returns square root of given value. More... | |
KZ_INLINE kzFloat | kzsFmod (kzFloat value, kzFloat divisor) |
Floating point remainder of value divided by divisor. More... | |
KZ_INLINE kzFloat | kzsModf (kzFloat value, kzFloat *intPart) |
Breaks floating point number to integral and fractional part. More... | |
KZ_INLINE kzUint | kzsRemainder (kzInt dividend, kzUint divisor) |
Returns modulo dividend % divisor for signed numbers in a way that negative numbers are treated as an extension instead of mirroring compared to positive numbers. More... | |
KZ_INLINE kzFloat | kzsRemainderf (kzFloat dividend, kzFloat divisor) |
Same as kzsRemainder, but for floating point numbers. More... | |
KZ_INLINE kzFloat | kzsPowf (kzFloat value, kzFloat exponent) |
Raises 'value' to the power of 'exponent'. More... | |
KZ_INLINE kzFloat | kzsExpf (kzFloat value) |
Raises e (base of natural logarithm) to the power of 'value'. More... | |
KZ_INLINE kzFloat | kzsLog10f (kzFloat value) |
Returns base 10 logarithm of given floating point value. More... | |
KZ_INLINE kzFloat | kzsFloorf (kzFloat value) |
Returns the largest integer not greater than value as float. More... | |
KZ_INLINE kzInt | kzsIFloorf (kzFloat value) |
Returns the largest integer not greater than value as integer. More... | |
KZ_INLINE kzFloat | kzsRoundf (kzFloat value) |
Returns the floating point value rounded as per normal rounding rules. More... | |
KZ_INLINE kzFloat | kzsCeilf (kzFloat value) |
Returns the smallest integer no less than value in float. More... | |
KZ_INLINE kzInt | kzsICeilf (kzFloat value) |
Returns the smallest integer no less than value in integer. More... | |
KZ_INLINE kzUint | kzsAbs (kzInt value) |
Returns absolute value from integer value. More... | |
KZ_INLINE kzFloat | kzsFabsf (kzFloat value) |
Returns absolute value from floating point number. More... | |
KZ_INLINE kzFloat | kzsClampf (kzFloat value, kzFloat minimum, kzFloat maximum) |
Clamps float value to given range. More... | |
KZ_INLINE kzInt | kzsClampi (kzInt value, kzInt minimum, kzInt maximum) |
Clamps integer value to given range. More... | |
KZ_INLINE kzUint | kzsClampui (kzUint value, kzUint minimum, kzUint maximum) |
Clamps unsigned integer value to given range. More... | |
KZ_INLINE kzFloat | kzsDegreesToRadians (kzFloat angleInDegrees) |
Converts degrees to radians. More... | |
KZ_INLINE kzFloat | kzsRadiansToDegrees (kzFloat angleInRadians) |
Converts radians to degrees. More... | |
KZ_INLINE kzBool | kzsIsInClosedInterval (kzFloat value, kzFloat minimum, kzFloat maximum) |
Check whether value is in [min, max] (an interval inclusive of the limit points) More... | |
KZ_INLINE kzBool | kzsFloatIsEqual (kzFloat valueA, kzFloat valueB) |
Check if two floats are equal. More... | |
KZ_INLINE kzBool | kzsFloatIsAlmostEqualUlps (kzFloat valueA, kzFloat valueB, kzUint maxUlps) |
Check if two IEEE 754 binary32 floats are equal up to a given number of ulps. More... | |
KZ_INLINE kzBool | kzsFloatIsAlmostEqualAbsolute (kzFloat valueA, kzFloat valueB, kzFloat maxAbsoluteDifference) |
Check if two floats are equal up to a given difference. More... | |
KZ_INLINE kzBool | kzsFloatIsAlmostEqualRelative (kzFloat valueA, kzFloat valueB, kzFloat maxRelativeDifference) |
Check if two floats are equal up to a given difference scaled by the larger value. More... | |
KZ_INLINE kzBool | kzsFloatIsAlmostEqual (kzFloat valueA, kzFloat valueB) |
Check if two floats are approximately equal. More... | |
KZ_INLINE kzInt | kzsMin (kzInt a, kzInt b) |
Returns the smaller of two integers. More... | |
KZ_INLINE kzInt | kzsMax (kzInt a, kzInt b) |
Returns the greater of two integers. More... | |
KZ_INLINE kzUint | kzsMinU (kzUint a, kzUint b) |
Returns the smaller of two unsigned integers. More... | |
KZ_INLINE kzUint | kzsMaxU (kzUint a, kzUint b) |
Returns the greater of two unsigned integers. More... | |
KZ_INLINE kzFloat | kzsMinf (kzFloat a, kzFloat b) |
Returns the smaller of two floats. More... | |
KZ_INLINE kzFloat | kzsMaxf (kzFloat a, kzFloat b) |
Returns the greater of two floats. More... | |
KZ_INLINE kzFloat | kzsStepf (kzFloat a, kzFloat b) |
Returns the step function of two floats. More... | |
KZ_INLINE void | kzsQsort (void *buffer, kzUint itemCount, kzUint itemSize, kzInt(*comparator)(const void *left, const void *right)) |
Sorts values in buffer using quick sort. More... | |
KZ_INLINE kzUint | kzsFloatToUint (kzFloat value) |
Casts a float to unsigned int. More... | |
KZ_INLINE kzFloat | kzsUintToFloat (kzUint value) |
Casts an unsigned int to float. More... | |
KZ_INLINE kzInt | kzsFloatRoundToInt (kzFloat value) |
Rounds a float to the nearest integer. More... | |
KZ_INLINE kzUint | kzsFloatRoundToUint (kzFloat value) |
Rounds a float to the nearest unsigned integer. More... | |
KZ_INLINE void | kzsSwap (void *element1, void *element2, kzUint elementSize) |
Swaps two arbitrary elements of arbitrary size. More... | |
Variables | |
KANZI_API const union KZ_FLOAT_UNION_TYPE | KZS_NAN_PRIVATE |
KANZI_API const union KZ_FLOAT_UNION_TYPE | KZS_INFINITY_PRIVATE |
Math wrappers.
Copyright 2008-2017 by Rightware. All rights reserved.
#define KZS_PI |
Mathematical constant pi.
#define KZS_E |
Mathematical constant e.
#define KZS_LN_2 |
Natural logarithm of 2.
#define KZ_FLOAT_MAXIMUM |
Largest value for a floating point number.
#define KZ_FLOAT_MINIMUM |
Most negative value for a floating point number.
#define KZ_FLOAT_SMALLEST_POSITIVE |
Smallest normalized value larger than positive zero.
#define KZ_FLOAT_EPSILON |
Smallest float such that 1.0f + KZ_FLOAT_EPSILON != 1.0f.
#define KZ_INT_MAXIMUM |
Largest value for integer.
#define KZ_INT_MINIMUM |
Smallest value for integer.
#define KZ_UINT_MAXIMUM |
Largest value for unsigned integer.
#define KZ_UINT32_MAXIMUM |
Largest value for 32-bit unsigned integer.
#define KZS_NAN |
Floating point value for Not a Number.
#define KZS_INFINITY |
Floating point value for positive infinity.
Negative infinity is -KZS_INFINITY.
Returns KZ_TRUE if x is the specific IEEE floating point positive infinity constant.
Returns inverse sine from floating point number between -1 and 1.
Returns inverse cosine from floating point number between -1 and 1.
Floating point remainder of value divided by divisor.
The result may be negative for negative values.
Breaks floating point number to integral and fractional part.
Returns fractional part as return value and sets intPart to integral part.
Returns modulo dividend % divisor for signed numbers in a way that negative numbers are treated as an extension instead of mirroring compared to positive numbers.
For example kzsRemainder(-16, 5) = 4
Same as kzsRemainder, but for floating point numbers.
Results are undefined if divisor is not greater than zero.
Raises 'value' to the power of 'exponent'.
Raises e (base of natural logarithm) to the power of 'value'.
Returns base 10 logarithm of given floating point value.
Returns the largest integer not greater than value as float.
Returns the largest integer not greater than value as integer.
Returns the floating point value rounded as per normal rounding rules.
Returns the smallest integer no less than value in float.
Returns the smallest integer no less than value in integer.
Clamps float value to given range.
Clamps integer value to given range.
Clamps unsigned integer value to given range.
Check whether value is in [min, max] (an interval inclusive of the limit points)
Check if two IEEE 754 binary32 floats are equal up to a given number of ulps.
KZ_INLINE kzBool kzsFloatIsAlmostEqualAbsolute | ( | kzFloat | valueA, |
kzFloat | valueB, | ||
kzFloat | maxAbsoluteDifference | ||
) |
Check if two floats are equal up to a given difference.
KZ_INLINE kzBool kzsFloatIsAlmostEqualRelative | ( | kzFloat | valueA, |
kzFloat | valueB, | ||
kzFloat | maxRelativeDifference | ||
) |
Check if two floats are equal up to a given difference scaled by the larger value.
Check if two floats are approximately equal.
Returns the step function of two floats.
KZ_INLINE void kzsQsort | ( | void * | buffer, |
kzUint | itemCount, | ||
kzUint | itemSize, | ||
kzInt(*)(const void *left, const void *right) | comparator | ||
) |
Sorts values in buffer using quick sort.
Rounds a float to the nearest unsigned integer.
Swaps two arbitrary elements of arbitrary size.
KANZI_API const union KZ_FLOAT_UNION_TYPE KZS_NAN_PRIVATE |
KANZI_API const union KZ_FLOAT_UNION_TYPE KZS_INFINITY_PRIVATE |