69 template<
typename T>
inline T
ABS (T x) {
return (x>=0) ? x : -x; }
70 template<
typename T>
inline T
MIN (T a, T b) {
return (a<b) ? a : b; }
71 template<
typename T>
inline T
MAX (T a, T b) {
return (a>b) ? a : b; }
72 template<
typename T>
inline T
CLIP (T v, T amin, T amax)
73 {
if (v < amin)
return amin;
else if (v > amax)
return amax;
else return v; }
78 template<
typename T>
inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
81 template<
typename T>
inline bool ISPOWER2(T x) {
return x && !(x & (x - 1)); }
90 x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16;
102 x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x |= x >> 32;
108 template<>
inline double ABS(
double x) {
return fabs(x); }
111 template<>
inline float ABS(
float x) {
return fabsf(x); }
115 template<>
inline double MIN(
double a,
double b) {
return fmin(a, b); }
118 template<>
inline float MIN(
float a,
float b) {
return fminf(a, b); }
122 template<>
inline double MAX(
double a,
double b) {
return fmax(a, b); }
125 template<>
inline float MAX(
float a,
float b) {
return fmaxf(a, b); }
131 #define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0])) 211 #endif // COMMON_UTIL_H
void void status(const char *s,...) GCC_PRINTF(1
Print a status message to both stderr and the global log file (if a global log file has been opened)...
Low-level macros and functions to handle different endianness portably.
float convertIEEEFloat(uint32 data)
Convert a uint32 holding the bit pattern of a 32-bit IEEE 754 single precision floating point value i...
void void void void NORETURN_PRE NORETURN_POST
void warning(const char *s,...) GCC_PRINTF(1
Print a warning message to both stderr and the global log file (if a global log file has been opened)...
static uint32 NEXTPOWER2(uint32 x)
Round up to the next power of 2.
bool ISPOWER2(T x)
Is this integer value a power of 2?
void void void void NORETURN_PRE error(const char *s,...) GCC_PRINTF(1
Print an error message to both stderr and the global log file (if a global log file has been opened)...
double convertIEEEDouble(uint64 data)
Convert a uint64 holding the bit pattern of a 64-bit IEEE 754 double precision floating point value i...
double readNintendoFixedPoint(uint32 value, bool sign, uint8 iBits, uint8 fBits)
Read a fixed-point value, in a format used by the Nintendo DS.
T CLIP(T v, T amin, T amax)
float readIEEEFloat16(uint16 value)
Read a half-precision 16-bit IEEE float, converting it into a 32-bit iEEE float.
void SWAP(T &a, T &b)
Template method which swaps the values of its two parameters.
void void void info(const char *s,...) GCC_PRINTF(1
Print an info message to both stdout and the global log file (if a global log file has been opened)...