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_TAU_F 6.283185307179586F
18#define M_PI_2_F (M_PI_F / 2.0F)
19#define M_PI_3_F (M_PI_F / 3.0F)
20
21#define M_PI_L 3.14159265358979323846L
22#define M_TAU_L 6.283185307179586L
23#define M_PI_2_L (M_PI_L / 2.0L)
24#define M_PI_3_L (M_PI_L / 3.0L)
25
26#define SIGNF(x) ((x) > 0.0f ? 1.0f : -1.0f)
27
28static float const deg_to_rad = M_PI / 180;
29static float const rad_to_deg = 180 / M_PI;
30
31#ifdef __MWERKS__
32#pragma push
33#pragma cplusplus on
34#endif
35
36#define FLT_EPSILON 1.00000001335e-10F
37
38#ifdef __MWERKS__
39#pragma pop
40#endif
41
49
50static inline s32 __fpclassifyf(float x)
51{
52 const s32 exp_mask = 0x7F800000;
53 const s32 mantissa_mask = 0x007FFFFF;
54 switch ((*(s32*) &x) & exp_mask) {
55 case exp_mask:
56 return ((*(s32*) &x) & mantissa_mask) ? FP_NAN : FP_INFINITE;
57 case 0:
58 return ((*(s32*) &x) & mantissa_mask) ? FP_SUBNORMAL : FP_ZERO;
59 default:
60 return FP_NORMAL;
61 }
62}
63
64extern int __HI(double);
65extern int __LO(double);
66
67static inline s32 __fpclassifyd(double x)
68{
69 switch (__HI(x) & 0x7ff00000) {
70 case 0x7ff00000:
71 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
72 ? FP_NAN
74 case 0:
75 return ((__HI(x) & 0x000fffff) || (__LO(x) & 0xffffffff))
77 : FP_ZERO;
78 default:
79 return FP_NORMAL;
80 }
81}
82
83#define fpclassify(x) \
84 ((sizeof(x) == sizeof(float)) ? __fpclassifyf((float) (x)) \
85 : __fpclassifyd((double) (x)))
86
87#define ABS(x) ((x) < 0 ? -(x) : (x))
88
89static inline double fabs(double f)
90{
91 return __fabs(f);
92}
93
94double frexp(double x, int* exponent);
95float fabsf__Ff(float);
96float tanf(float x);
97float cos__Ff(float x);
98float sin__Ff(float x);
99float cosf(float x);
100float sinf(float x);
101void __sinit_trigf_c(void);
102float logf(float);
103
104#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)
static float const deg_to_rad
Definition itparasol.c:16
#define M_PI
Definition itparasol.c:15
float sin__Ff(float x)
double frexp(double x, int *exponent)
Definition math_1.c:11
static s32 __fpclassifyd(double x)
Definition math.h:67
float fabsf__Ff(float)
Definition math_1.c:6
float cos__Ff(float x)
static double fabs(double f)
Definition math.h:89
float tanf(float x)
float cosf(float x)
float logf(float)
Definition math.c:66
float sinf(float x)
static s32 __fpclassifyf(float x)
Definition math.h:50
FloatType
Definition math.h:42
@ FP_INFINITE
Definition math.h:44
@ FP_SUBNORMAL
Definition math.h:47
@ FP_NORMAL
Definition math.h:46
@ FP_ZERO
Definition math.h:45
@ FP_NAN
Definition math.h:43
void __sinit_trigf_c(void)
Definition trigf.c:14
static float const rad_to_deg
Definition math.h:29