00001 #ifndef _SYS_NTMath_h_
00002 #define _SYS_NTMath_h_
00003
00004 #include "SYS_API.h"
00005 #include "SYS_Types.h"
00006
00007 #if defined(CELLRSX)
00008 #include <ppu_intrinsics.h>
00009 #endif
00010
00011 #if !defined(M_SQRT2)
00012 #define M_SQRT2 1.41421356237309504880
00013 #endif
00014
00015 #ifdef WIN32
00016 #include <stdlib.h>
00017 #include <math.h>
00018
00019 #define SYS_HAS_NO_DRAND
00020 #define SYS_HAS_NO_RANDOM
00021 #define SYS_HAS_NO_PI
00022
00023 #define finite(x) _finite(x)
00024 #define isfinite(x) _finite(x)
00025
00026 #ifdef __cplusplus
00027 #include <ieeefp.h>
00028
00029
00030 static inline fpreal32 truncf(fpreal32 value)
00031 {
00032 return (value < 0.0f) ? ceilf(value) : floorf(value);
00033 }
00034
00035 static inline fpreal64 trunc(fpreal64 value)
00036 {
00037 return (value < 0.0) ? ceil(value) : floor(value);
00038 }
00039
00040 static inline fpreal64 cbrt(fpreal64 x)
00041 {
00042
00043
00044
00045 if (x < 0)
00046 return -pow(-x, 1.0/3.0);
00047 else
00048 return pow(x, 1.0/3.0);
00049 }
00050 #endif
00051 #endif
00052
00053 #if defined(GAMEOS)
00054 #define SYS_HAS_NO_DRAND
00055 #define SYS_HAS_NO_RANDOM
00056 #define SYS_HAS_NO_PI
00057 static inline int finite(double) { return 1; }
00058 #endif
00059
00060 #if defined(SYS_HAS_NO_DRAND) && defined(__cplusplus)
00061 SYS_API double NTdrand48();
00062 SYS_API double NTerand48(short seed[3]);
00063 SYS_API void NTsrand48(long);
00064 inline void srand48(long x)
00065 { NTsrand48(x); }
00066 inline double drand48()
00067 { return NTdrand48(); }
00068 #endif
00069
00070 #if defined(SYS_HAS_NO_RANDOM) && defined(__cplusplus)
00071 SYS_API char *NTinitstate(unsigned int seed, char *state, int n);
00072 SYS_API char *NTsetstate(char *state);
00073 SYS_API void NTsrandom(unsigned int);
00074 SYS_API long NTrandom();
00075 inline long random()
00076 { return NTrandom(); }
00077 inline void srandom(unsigned int x)
00078 { NTsrandom(x); }
00079 inline char *initstate(unsigned int seed, char *state, int n)
00080 { return NTinitstate(seed, state, n); }
00081 inline char *setstate(char *state)
00082 { return NTsetstate(state); }
00083 #endif
00084
00085 #if defined(SYS_HAS_NO_PI)
00086 #undef M_PI
00087 #undef M_PI_2
00088 #undef M_PI_4
00089 #define M_PI 3.14159265358979323846F
00090 #define M_PI_2 1.57079632679489661923F
00091 #define M_PI_4 0.78539816339744830962F
00092 #endif
00093
00094 #endif