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_TAU 6.283185307179586
13#define M_PI_2 (M_PI / 2)
14#define M_PI_3 (M_PI / 3)
15
16#define M_PI_F 3.14159265358979323846F
17#define M_PI_2_F (M_PI_F / 2.0F)
18#define M_PI_3_F (M_PI_F / 3.0F)
19
20#define M_PI_L 3.14159265358979323846L
21#define M_TAU_L 6.283185307179586L
22#define M_PI_2_L (M_PI_L / 2.0L)
23#define M_PI_3_L (M_PI_L / 3.0L)
24
25static float const deg_to_rad = M_PI / 180;
26static float const rad_to_deg = 180 / M_PI;
27
28#ifdef __MWERKS__
29#pragma push
30#pragma cplusplus on
31#endif
32
33#define FLT_EPSILON 1.00000001335e-10F
34
35#ifdef __MWERKS__
36#pragma pop
37#endif
38
46
47static inline s32 __fpclassifyf(float x)
48{
49 const s32 exp_mask = 0b01111111100000000000000000000000; // = 0x7F800000
50 const s32 mantissa_mask =
51 0b00000000011111111111111111111111; // = 0x007fffff
52 switch ((*(s32*) &x) & exp_mask) {
53 case exp_mask:
54 return ((*(s32*) &x) & mantissa_mask) ? FP_NAN : FP_INFINITE;
55 case 0:
56 return ((*(s32*) &x) & mantissa_mask) ? FP_SUBNORMAL : FP_ZERO;
57 default:
58 return FP_NORMAL;
59 }
60}
61
62extern int __HI(double);
63extern int __LO(double);
64
65static inline s32 __fpclassifyd(double x)
66{
67 switch (__HI(x) & 0x7ff00000) {
68 case 0x7ff00000:
69 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
70 ? FP_NAN
72 case 0:
73 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
75 : FP_ZERO;
76 default:
77 return FP_NORMAL;
78 }
79}
80
81#define fpclassify(x) \
82 ((sizeof(x) == sizeof(float)) ? __fpclassifyf((float) (x)) \
83 : __fpclassifyd((double) (x)))
84
85#define ABS(x) ((x) < 0 ? -(x) : (x))
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
#define __LO(x)
Definition ansi_fp.c:6
#define __HI(x)
Definition ansi_fp.c:5
signed long s32
Definition hsd_3B2B.h:1
double __fabs(double)
float sin__Ff(float x)
double frexp(double x, int *exponent)
Definition math_1.c:11
static s32 __fpclassifyd(double x)
Definition math.h:65
float fabsf__Ff(float)
Definition math_1.c:6
float cos__Ff(float x)
static double fabs(double f)
Definition math.h:87
float tanf(float x)
float cosf(float x)
float logf(float)
Definition math.c:65
float sinf(float x)
static s32 __fpclassifyf(float x)
Definition math.h:47
FloatType
Definition math.h:39
@ FP_INFINITE
Definition math.h:41
@ FP_SUBNORMAL
Definition math.h:44
@ FP_NORMAL
Definition math.h:43
@ FP_ZERO
Definition math.h:42
@ FP_NAN
Definition math.h:40
static float const deg_to_rad
Definition math.h:25
void __sinit_trigf_c(void)
Definition trigf.c:14
static float const rad_to_deg
Definition math.h:26
#define M_PI
Definition math.h:11