#include <nitro/math.h>
static inline int MATH_IAbs( int a );
static inline int MATH_IMin( int a , int b );
static inline int MATH_IMax( int a , int b );
MATH_ABS( a );
MATH_MIN( a , b );
MATH_MAX( a , b );
MATH_CLAMP( x , low , high );
MATH_ROUNDUP( x , base );
MATH_ROUNDDOWN( x , base );
MATH_ROUNDUP32( x );
MATH_ROUNDDOWN32( x );
This is the group of utility functions.
MATH_IAbs | Inline function that returns an int-type argument's absolute value. |
MATH_IMin | Inline function that compares two int-type arguments and returns the smaller. |
MATH_IMax | Inline function that compares two int-type arguments and returns the larger. |
MATH_ABS | Function macro that returns argument's absolute value. Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments. |
MATH_MIN | Function macro that compares two arguments and returns the smaller. Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments. |
MATH_MAX | Function macro that compares two arguments and returns the larger. Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments. |
MATH_CLAMP | Function macro that returns value holding range from low to high in argument. Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments. |
MATH_ROUNDUP | Function macro that returns the value of the 1st argument, x, rounded up to a multiple of the 2nd argument, base. In other words, it returns the smallest multiple of base that is greater or equal to x. base must be a multiple of 2. |
MATH_ROUNDDOWN | Function macro that returns the value of the 1st argument, x, rounded down to a multiple of the 2nd argument, base. In other words, it returns the largest multiple of base that is less than or equal to x. base must be a multiple of 2. |
MATH_ROUNDUP32 | Function macro that returns value of argument rounded up to a multiple of 32. The same as executing MATH_ROUNDUP(x, 32) |
MATH_ROUNDDOWN32 | Function macro that returns value of argument rounded down to a multiple of 32. The same as executing MATH_ROUNDDOWN(x, 32) |
#define MATH_ABS(a) (((a) < 0 ) ? (-(a)) : (a)) #define MATH_MIN(a,b) (((a) <= (b)) ? (a) : (b)) #define MATH_MAX(a,b) (((a) >= (b)) ? (a) : (b)) #define MATH_CLAMP(x, low, high) ( ( (x) > (high) ) ? (high) : ( ( (x) < (low) ) ? (low) : (x) ) ) #define MATH_ROUNDUP(x, base) (((x) + ((base)-1)) & ~((base)-1)) #define MATH_ROUNDDOWN(x, base) ((x) & ~((base)-1)) #define MATH_ROUNDUP32(x) MATH_ROUNDUP(x, 32) #define MATH_ROUNDDOWN32(x) MATH_ROUNDDOWN(x, 32)
None.
06/02/2005 Changed & to &.
12/14/2004 Initial version.