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#ifdef __MWERKS__
37 double guess = __frsqrte((double) x); // returns an approximation to
38#else
39 double guess;
40 asm("frsqrte %0, %1" : "=f"(guess) : "f"(x));
41#endif
42 guess = _half * guess *
43 (_three - guess * guess * x); // now have 12 sig bits
44 guess = _half * guess *
45 (_three - guess * guess * x); // now have 24 sig bits
46 guess = _half * guess *
47 (_three - guess * guess * x); // now have 32 sig bits
48 y = (float) (x * guess);
49 return y;
50 }
51 return x;
52}
53
54// TODO: this isn't correct! It's just to generate sdata2 in GXDraw.o
55extern inline float sqrt(float x)
56{
57 static const double _half = .5;
58 static const double _three = 3.0;
59 volatile float y;
60 if (x > 0.0f) {
61#ifdef __MWERKS__
62 double guess = __frsqrte((double) x); // returns an approximation to
63#else
64 double guess;
65 asm("frsqrte %0, %1" : "=f"(guess) : "f"(x));
66#endif
67 guess = _half * guess *
68 (_three - guess * guess * x); // now have 12 sig bits
69 guess = _half * guess *
70 (_three - guess * guess * x); // now have 24 sig bits
71 guess = _half * guess *
72 (_three - guess * guess * x); // now have 32 sig bits
73 y = (float) (x * guess);
74 return y;
75 }
76 return x;
77}
78
79#ifdef __MWERKS__
80#define fabs(x) __fabs(x)
81#define fabsf(x) __fabsf(x)
82#else
83double fabs(double x);
84float fabsf(float x);
85#endif
86
87long __fpclassifyf(float x);
88long __fpclassifyd(double x);
89
90#define FP_NAN 1
91#define FP_INFINITE 2
92#define FP_ZERO 3
93#define FP_NORMAL 4
94#define FP_SUBNORMAL 5
95
96#define fpclassify(x) \
97 (sizeof(x) == sizeof(float) ? __fpclassifyf((float) (x)) \
98 : __fpclassifyd((double) (x)))
99#define isfinite(x) ((fpclassify(x) > FP_INFINITE))
100
101inline float fmodf(float x, float m)
102{
103 float a = fabsf(m);
104 float b = fabsf(x);
105 if (a > b) {
106 return x;
107 } else {
108 long long c = (long long) (x / m);
109 return x - m * c;
110 }
111}
112
113#ifdef __MWERKS__
114#pragma cplusplus reset
115#endif
116
117#endif
double scalbn(double x, int n)
float sqrtf(float x)
Definition math.h:30
float sqrt(float x)
Definition math.h:55
double cos(double x)
float tanf(float x)
Definition trigf.c:126
double floor(double x)
float cosf(float x)
Definition trigf.c:68
long __fpclassifyd(double x)
float sinf(float x)
Definition trigf.c:24
float fmodf(float x, float m)
Definition math.h:101
double fabs(double x)
float acosf(float x)
Definition lbtrigf.c:45
float fabsf(float x)
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
#define __frsqrte(x)
Definition placeholder.h:13
int c
Definition tev.c:10
GXColorS10 a
Definition tev.c:9