SSBM Decomp
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1#ifndef _MATH_H_
2#define _MATH_H_
3
4#define NAN (0.0f / 0.0f)
5#define HUGE_VALF (1.0f / 0.0f)
6#define INFINITY (1.0f / 0.0f)
7
8double fabs(double x);
9double sin(double x);
10double cos(double x);
11
12float sinf(float x);
13float cosf(float x);
14float tanf(float x);
15float acosf(float x);
16float powf(float base, float exponent);
17
18double ldexp(double x, int exp);
19
20double scalbn(double x, int n);
21
22double copysign(double x, double y);
23
24#ifdef __MWERKS__
25#pragma cplusplus on
26#endif
27
28double floor(double x);
29
30extern inline float sqrtf(float x)
31{
32 static const double _half = .5;
33 static const double _three = 3.0;
34 volatile float y;
35 if (x > 0.0f)
36 {
37#ifdef __MWERKS__
38 double guess = __frsqrte((double)x); // returns an approximation to
39#else
40 double guess;
41 asm("frsqrte %0, %1" : "=f"(guess) : "f"(x));
42#endif
43 guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
44 guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
45 guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
46 y = (float)(x*guess);
47 return y ;
48 }
49 return x;
50}
51
52// TODO: this isn't correct! It's just to generate sdata2 in GXDraw.o
53extern inline float sqrt(float x)
54{
55 static const double _half = .5;
56 static const double _three = 3.0;
57 volatile float y;
58 if (x > 0.0f)
59 {
60#ifdef __MWERKS__
61 double guess = __frsqrte((double)x); // returns an approximation to
62#else
63 double guess;
64 asm("frsqrte %0, %1" : "=f"(guess) : "f"(x));
65#endif
66 guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
67 guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
68 guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
69 y = (float)(x*guess);
70 return y ;
71 }
72 return x;
73}
74
75#ifdef __MWERKS__
76#define fabs(x) __fabs(x)
77#define fabsf(x) __fabsf(x)
78#else
79double fabs(double x);
80float fabsf(float x);
81#endif
82
83long __fpclassifyf(float x);
84long __fpclassifyd(double x);
85
86#define FP_NAN 1
87#define FP_INFINITE 2
88#define FP_ZERO 3
89#define FP_NORMAL 4
90#define FP_SUBNORMAL 5
91
92#define fpclassify(x) (sizeof(x) == sizeof(float) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)))
93#define isfinite(x) ((fpclassify(x) > FP_INFINITE))
94
95inline float fmodf(float x, float m)
96{
97 float a = fabsf(m);
98 float b = fabsf(x);
99 if (a > b)
100 return x;
101 else
102 {
103 long long c = (long long)(x / m);
104 return x - m * c;
105 }
106}
107
108#ifdef __MWERKS__
109#pragma cplusplus reset
110#endif
111
112#endif
double scalbn(double x, int n)
float sqrtf(float x)
Definition math.h:30
float sqrt(float x)
Definition math.h:53
double cos(double x)
float tanf(float x)
Definition trigf.c:125
double floor(double x)
float cosf(float x)
Definition trigf.c:70
long __fpclassifyd(double x)
float sinf(float x)
Definition trigf.c:26
float fmodf(float x, float m)
Definition math.h:95
double fabs(double x)
float acosf(float x)
Definition lbtrigf.c:40
long __fpclassifyf(float x)
double sin(double x)
double ldexp(double x, int exp)
double copysign(double x, double y)
float powf(float base, float exponent)
Definition lb_00CE.c:63
double __frsqrte(double)
#define fabsf
Definition psdisp.c:18
int c
Definition tev.c:12
GXColorS10 a
Definition tev.c:11