SSBM Decomp
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1#ifndef MSL_MATH_H
2#define MSL_MATH_H
3
4#include <platform.h>
5
7
8#define MSL_HI(x) *(int*) &x
9#define MSL_LO(x) *(1 + (int*) &x)
10
11#define M_PI 3.14159265358979323846
12#define M_PI_2 (M_PI / 2)
13#define M_PI_3 (M_PI / 3)
14
15static float const deg_to_rad = M_PI / 180;
16static float const rad_to_deg = 180 / M_PI;
17
18#ifdef __MWERKS__
19#pragma push
20#pragma cplusplus on
21#endif
22
23#define FLT_EPSILON 1.00000001335e-10F
24
25#ifdef __MWERKS__
26#pragma pop
27#endif
28
36
37static inline s32 __fpclassifyf(float x)
38{
39 const s32 exp_mask = 0b01111111100000000000000000000000; // = 0x7F800000
40 const s32 mantissa_mask =
41 0b00000000011111111111111111111111; // = 0x007fffff
42 switch ((*(s32*) &x) & exp_mask) {
43 case exp_mask:
44 return ((*(s32*) &x) & mantissa_mask) ? FP_NAN : FP_INFINITE;
45 case 0:
46 return ((*(s32*) &x) & mantissa_mask) ? FP_SUBNORMAL : FP_ZERO;
47 default:
48 return FP_NORMAL;
49 }
50}
51
52extern int __HI(double);
53extern int __LO(double);
54
55static inline s32 __fpclassifyd(double x)
56{
57 switch (__HI(x) & 0x7ff00000) {
58 case 0x7ff00000:
59 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
60 ? FP_NAN
62 case 0:
63 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
65 : FP_ZERO;
66 default:
67 return FP_NORMAL;
68 }
69}
70
71#define fpclassify(x) \
72 ((sizeof(x) == sizeof(float)) ? __fpclassifyf((float) (x)) \
73 : __fpclassifyd((double) (x)))
74
76#define ABS(x) ((x) < 0 ? -(x) : (x))
77
78static inline f32 fabs_inline(f32 x)
79{
80 if (x < 0) {
81 return -x;
82 } else {
83 return x;
84 }
85}
86
87static inline double fabs(double f)
88{
89 return __fabs(f);
90}
91
92double frexp(double x, int* exponent);
93float fabsf__Ff(float);
94float tanf(float x);
95float cos__Ff(float x);
96float sin__Ff(float x);
97float cosf(float x);
98float sinf(float x);
99void __sinit_trigf_c(void);
100float logf(float);
101
102#endif
double __fabs(double)
float sin__Ff(float x)
Definition trigf.c:20
double frexp(double x, int *exponent)
Definition math_1.c:6
static s32 __fpclassifyd(double x)
Definition math.h:55
int __HI(double)
int __LO(double)
float fabsf__Ff(float)
Definition math_1.c:28
float cos__Ff(float x)
Definition trigf.c:15
static double fabs(double f)
Definition math.h:87
float tanf(float x)
Definition trigf.c:10
float cosf(float x)
Definition trigf.c:42
float logf(float)
Definition math.c:105
float sinf(float x)
Definition trigf.c:103
static s32 __fpclassifyf(float x)
Definition math.h:37
FloatType
Definition math.h:29
@ FP_INFINITE
Definition math.h:31
@ FP_SUBNORMAL
Definition math.h:34
@ FP_NORMAL
Definition math.h:33
@ FP_ZERO
Definition math.h:32
@ FP_NAN
Definition math.h:30
static float const deg_to_rad
Definition math.h:15
void __sinit_trigf_c(void)
Definition trigf.c:171
static float const rad_to_deg
Definition math.h:16
static f32 fabs_inline(f32 x)
Definition math.h:78
#define M_PI
Definition math.h:11
float f32
A 32-bit floating-point number.
Definition platform.h:62
signed long s32
A signed 32-bit integer.
Definition platform.h:14