33
44#define M_PI 3.14159265358979323846f
55
6- #define NAN (0.0f / 0.0f)
6+ #define NAN (0.0f / 0.0f)
77#define HUGE_VALF (1.0f / 0.0f)
8- #define INFINITY (1.0f / 0.0f)
8+ #define INFINITY (1.0f / 0.0f)
99
1010double fabs (double x );
1111double sin (double x );
@@ -27,49 +27,51 @@ double copysign(double x, double y);
2727#pragma cplusplus on
2828#endif
2929
30+ #ifdef __cplusplus
31+ extern "C" {
32+ #endif
33+
3034double floor (double x );
35+ double fmod (double x , double y );
36+ double pow (double x , double y );
3137
32- extern inline float sqrtf (float x )
33- {
38+ extern inline float sqrtf (float x ) {
3439 static const double _half = .5 ;
3540 static const double _three = 3.0 ;
3641 volatile float y ;
37- if (x > 0.0f )
38- {
42+ if (x > 0.0f ) {
3943#ifdef __MWERKS__
40- double guess = __frsqrte ((double )x ); // returns an approximation to
44+ double guess = __frsqrte ((double )x ); // returns an approximation to
4145#else
4246 double guess ;
4347 asm("frsqrte %0, %1" : "=f" (guess ) : "f" (x ));
4448#endif
45- guess = _half * guess * (_three - guess * guess * x ); // now have 12 sig bits
46- guess = _half * guess * (_three - guess * guess * x ); // now have 24 sig bits
47- guess = _half * guess * (_three - guess * guess * x ); // now have 32 sig bits
48- y = (float )(x * guess );
49- return y ;
49+ guess = _half * guess * (_three - guess * guess * x ); // now have 12 sig bits
50+ guess = _half * guess * (_three - guess * guess * x ); // now have 24 sig bits
51+ guess = _half * guess * (_three - guess * guess * x ); // now have 32 sig bits
52+ y = (float )(x * guess );
53+ return y ;
5054 }
5155 return x ;
5256}
5357
5458// TODO: this isn't correct! It's just to generate sdata2 in GXDraw.o
55- extern inline float sqrt (float x )
56- {
59+ extern inline float sqrt (float x ) {
5760 static const double _half = .5 ;
5861 static const double _three = 3.0 ;
5962 volatile float y ;
60- if (x > 0.0f )
61- {
63+ if (x > 0.0f ) {
6264#ifdef __MWERKS__
63- double guess = __frsqrte ((double )x ); // returns an approximation to
65+ double guess = __frsqrte ((double )x ); // returns an approximation to
6466#else
6567 double guess ;
6668 asm("frsqrte %0, %1" : "=f" (guess ) : "f" (x ));
6769#endif
68- guess = _half * guess * (_three - guess * guess * x ); // now have 12 sig bits
69- guess = _half * guess * (_three - guess * guess * x ); // now have 24 sig bits
70- guess = _half * guess * (_three - guess * guess * x ); // now have 32 sig bits
71- y = (float )(x * guess );
72- return y ;
70+ guess = _half * guess * (_three - guess * guess * x ); // now have 12 sig bits
71+ guess = _half * guess * (_three - guess * guess * x ); // now have 24 sig bits
72+ guess = _half * guess * (_three - guess * guess * x ); // now have 32 sig bits
73+ y = (float )(x * guess );
74+ return y ;
7375 }
7476 return x ;
7577}
@@ -85,28 +87,31 @@ float fabsf(float x);
8587long __fpclassifyf (float x );
8688long __fpclassifyd (double x );
8789
88- #define FP_NAN 1
89- #define FP_INFINITE 2
90- #define FP_ZERO 3
91- #define FP_NORMAL 4
90+ #define FP_NAN 1
91+ #define FP_INFINITE 2
92+ #define FP_ZERO 3
93+ #define FP_NORMAL 4
9294#define FP_SUBNORMAL 5
9395
9496#define fpclassify (x ) (sizeof(x) == sizeof(float) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)))
9597#define isfinite (x ) ((fpclassify(x) > FP_INFINITE))
9698
97- inline float fmodf (float x , float m )
98- {
99- float a = fabsf (m );
100- float b = fabsf (x );
101- if (a > b )
102- return x ;
103- else
104- {
105- long long c = (long long )(x / m );
106- return x - m * c ;
107- }
99+ inline float fmodf (float x , float y ) {
100+ return fmod (x , y );
101+ }
102+
103+ inline float floorf (float x ) {
104+ return floor (x );
108105}
109106
107+ inline float powf (float x , float y ) {
108+ return pow (x , y );
109+ }
110+
111+ #ifdef __cplusplus
112+ }
113+ #endif
114+
110115#ifdef __MWERKS__
111116#pragma cplusplus reset
112117#endif
0 commit comments