Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
sdk_math.h
Go to the documentation of this file.
1// fake MSL_C math for sdk specifically since it differs from game MSL_C math
2
3extern inline float sqrtf(float x) {
4 static const double _half=.5;
5 static const double _three=3.0;
6 volatile float y;
7 if(x > 0.0f) {
8 double guess = __frsqrte((double)x); // returns an approximation to
9 guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
10 guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
11 guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
12 y=(float)(x*guess);
13 return y ;
14 }
15 return x ;
16}
17
18extern inline float sqrt(float x) {
19 static const double _half=.5;
20 static const double _three=3.0;
21 volatile float y;
22 if(x > 0.0f) {
23 double guess = __frsqrte((double)x); // returns an approximation to
24 guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
25 guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
26 guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
27 guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
28
29 y=(float)(x*guess);
30 return y ;
31 }
32 return x ;
33}
34
35extern inline float fabs(float x) {
36#if __MIPS__
37 return fabsf(x);
38#else
39 (*(int*)&x)&=0x7fffffff;
40 return x;
41#endif
42}
43
44extern inline float fabsf(float x) {
45 return __fabsf(x);
46}
47
48extern float cosf(float);
49extern float sinf(float);
50extern float tanf(float);
51extern float acosf(float);
52
53extern inline float cos(float x) {
54 return cosf(x);
55}
56
57inline float floor(float x) {
58 int i=(int)x;
59 float y=x-(float)i;
60
61 if(!y || x > 8388608.0f)
62 return x ; // x is already an int
63
64 if(x < 0)
65 return (float)--i;
66 // x < 0 -> int conversion of x above rounded toward zero(so decrement)
67 return (float)i;
68}
float cosf(float)
Definition math_ppc.c:23
float fabs(float x)
Definition sdk_math.h:35
float tanf(float)
Definition math_ppc.c:31
float sinf(float)
Definition math_ppc.c:27
float sqrtf(float x)
Definition sdk_math.h:3
float sqrt(float x)
Definition sdk_math.h:18
float acosf(float)
Definition math_ppc.c:19
float cos(float x)
Definition sdk_math.h:53
float fabsf(float x)
Definition sdk_math.h:44
float floor(float x)
Definition sdk_math.h:57
double x double x
Definition e_atan2.c:58
double x double y
Definition e_atan2.c:58
int i
Definition e_log.c:92