#ifndef osml_math_h #define osml_math_h #if defined(__APPLE__) #include #include // Apple GCC for 32-bit PowerPC, Mac OS X 10.x #define OSML_PI 3.141592654f #define OSML_HALF_PI 1.570796327f #define OSML_TWO_PI 6.283185308f #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3 // No hardware sqrt or sqrtf function. // There's probably scope for an ASM version utilizing __frsqrtes OSML_INLINE float osml_sqrtf(float x) { return sqrt(x); } OSML_INLINE float osml_reciprocal_sqrtf(float x) { return 1.0 / sqrt(x); } // No math library support for sinf, cosf or tanf OSML_INLINE float osml_sinf(float x) { return sin(x); } OSML_INLINE float osml_cosf(float x) { return cos(x); } OSML_INLINE float osml_tanf(float x) { return tan(x); } #else // No hardware sqrt or sqrtf function. // There's probably scope for an ASM version utilizing __frsqrtes OSML_INLINE float osml_sqrtf(float x) { return sqrtf(x); } OSML_INLINE float osml_reciprocal_sqrtf(float x) { return 1.0f / sqrtf(x); } OSML_INLINE float osml_sinf(float x) { return sinf(x); } OSML_INLINE float osml_cosf(float x) { return cosf(x); } OSML_INLINE float osml_tanf(float x) { return tanf(x); } #endif #elif defined(linux) && defined(i386) #include // GCC for 32-bit Intel #define OSML_PI 3.141592654f #define OSML_HALF_PI 1.570796327f #define OSML_TWO_PI 6.283185308f OSML_INLINE float osml_sqrtf(float x) { return sqrtf(x); } OSML_INLINE float osml_reciprocal_sqrtf(float x) { return 1.0 / sqrtf(x); } OSML_INLINE float osml_sinf(float x) { return sinf(x); } OSML_INLINE float osml_cosf(float x) { return cosf(x); } OSML_INLINE float osml_tanf(float x) { return tanf(x); } #else #error Unknown compiler or OS #endif #endif OSML_INLINE float osml_square(float f) { return f * f; } OSML_INLINE float osml_cube(float f) { return f * f * f; } OSML_INLINE float osml_lerp(float a, float b, float fraction) { return a + fraction * (b - a); }