Macros | Functions
math.h File Reference

Math functions like overflow aware addition. More...

Macros

#define VTM_MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define VTM_MAX(a, b)   ((a) > (b) ? (a) : (b))
 

Functions

VTM_API int vtm_math_size_add (size_t a, size_t b, size_t *r)
 
VTM_API int vtm_math_size_mul (size_t a, size_t b, size_t *r)
 
VTM_API bool vtm_math_float_cmp (float a, float b, float epsilon)
 
VTM_API bool vtm_math_double_cmp (double a, double b, double epsilon)
 

Macro Definition Documentation

#define VTM_MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Evaluates to the smaller argument

#define VTM_MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Evaluates to the greater argument

Function Documentation

VTM_API int vtm_math_size_add ( size_t  a,
size_t  b,
size_t *  r 
)

Overflow aware addition of two size_t values.

Parameters
afirst value
bsecond value
[out]rthe result of the addion
Returns
VTM_OK if the addition has not resulted in an overflow
VTM_E_OVERFLOW if the addition would cause an overflow
VTM_API int vtm_math_size_mul ( size_t  a,
size_t  b,
size_t *  r 
)

Overflow aware multiplication of two size_t values.

Parameters
athe multiplicand
bthe multiplier
[out]rthe result
Returns
VTM_OK if the multiplication has not resulted in an overflow
VTM_E_OVERFLOW if the multiplication would cause an overflow
VTM_API bool vtm_math_float_cmp ( float  a,
float  b,
float  epsilon 
)

Compares two float values for (relative) equality.

Parameters
athe first input float
bthe second input float
epsilonthe precision threshold
VTM_API bool vtm_math_double_cmp ( double  a,
double  b,
double  epsilon 
)

Compares two double values for (relative) equality.

Parameters
athe first input double
bthe second input double
epsilonthe precision threshold