Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
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 "global.h"
5#include "float.h"
6
7#define NAN (*(float*) __float_nan)
8#define HUGE_VALF (*(float*) __float_huge)
9
10#define M_PI 3.14159265358979323846f
11#define M_SQRT3 1.73205f
12
13#define DEG_TO_RAD(degrees) (degrees * (M_PI / 180.0f))
14#define RAD_TO_DEG(radians) (radians * (180.0f / M_PI))
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20int abs(int);
21double acos(double);
22float acosf(float);
23double asin(double);
24double atan(double);
25double atan2(double, double);
26
27double ceil(double);
28inline float ceilf(float num) {
29 return ceil(num);
30}
31
32double copysign(double, double);
33double cos(double);
34float cosf(float);
35double exp(double);
36
37inline float expf(float x) {
38 return exp(x);
39}
40
41extern double __frsqrte(double);
42extern float __fres(float);
43
44extern double __fabs(double);
45extern float __fabsf(float);
46inline double fabs(double f) {
47 return __fabs(f);
48}
49inline double fabsf2(float f) {
50 return __fabsf(f);
51}
52inline float fabsf(float f) {
53 return fabsf2(f);
54}
55
56double floor(double);
57inline float floorf(float num) {
58 return floor(num);
59}
60
61double fmod(double, double);
62inline float fmodf(float f1, float f2) {
63 return fmod(f1, f2);
64}
65
66double frexp(double, int*);
67double ldexp(double, int);
68double modf(double, double*);
69double pow(double, double);
70float powf(float, float);
71double sin(double);
72float sinf(float);
73double sqrt(double);
74double tan(double);
75float tanf(float);
76
77#if PLATFORM_WII || PLATFORM_SHIELD
78inline float sqrtf(float mag) {
79 return sqrt(mag);
80}
81#else
82#ifdef DECOMPCTX
83// Hack to mitigate fake mismatches when building from decompctx output
84// (which doesn't support precompiled headers).
85//
86// When built without a PCH, these constants would end up .rodata instead of .data
87// which causes a variety of knock-on effects in individual functions' assembly.
88//
89// Making them into globals is a bit of a hack, but it generally fixes later
90// .data and .rodata offsets and allows individual functions to match.
91static double _half = 0.5;
92static double _three = 3.0;
93#endif
94inline float sqrtf(float mag) {
95#ifndef DECOMPCTX
96 // part of the same hack, these are defined outside of the function when using decompctx
97 static const double _half = 0.5;
98 static const double _three = 3.0;
99#endif
100 if (mag > 0.0f) {
101 double tmpd = __frsqrte(mag);
102 tmpd = tmpd * _half * (_three - mag * (tmpd * tmpd));
103 tmpd = tmpd * _half * (_three - mag * (tmpd * tmpd));
104 tmpd = tmpd * _half * (_three - mag * (tmpd * tmpd));
105 return mag * tmpd;
106 } else if (mag < 0.0) {
107 return NAN;
108 } else if (isnan(mag)) {
109 return NAN;
110 } else {
111 return mag;
112 }
113}
114#endif
115
116inline float atan2f(float y, float x) {
117 return (float)atan2(y, x);
118}
119
120inline float i_sinf(float x) { return sin(x); }
121inline float i_cosf(float x) { return cos(x); }
122inline float i_tanf(float x) { return tan(x); }
123inline float i_acosf(float x) { return acos(x); }
124
125#ifdef __cplusplus
126};
127#endif
128
129#endif
double x double x
Definition e_atan2.c:58
double x double y
Definition e_atan2.c:58
double atan2(double, double)
Definition w_atan2.c:3
float cosf(float)
Definition d_kankyo.cpp:42
float expf(float x)
Definition math.h:37
static double _half
Definition math.h:91
int abs(int)
Definition arith.c:3
float tanf(float)
Definition math_ppc.c:29
float powf(float, float)
Definition w_pow.c:7
float sinf(float)
Definition d_kankyo.cpp:38
float floorf(float num)
Definition math.h:57
float i_cosf(float x)
Definition math.h:121
float i_tanf(float x)
Definition math.h:122
float sqrtf(float mag)
Definition math.h:78
double ceil(double)
double frexp(double, int *)
double acos(double)
Definition w_acos.c:3
float acosf(float)
Definition math_ppc.c:17
double modf(double, double *)
double cos(double)
double fmod(double, double)
Definition w_fmod.c:3
float __fabsf(float)
double __fabs(double)
static double _three
Definition math.h:92
double copysign(double, double)
double pow(double, double)
Definition w_pow.c:3
float fmodf(float f1, float f2)
Definition math.h:62
double floor(double)
double ldexp(double, int)
Definition s_ldexp.c:22
double atan(double)
double __frsqrte(double)
double fabs(double f)
Definition math.h:46
float i_acosf(float x)
Definition math.h:123
float fabsf(float f)
Definition math.h:52
double tan(double)
double sqrt(double)
Definition w_sqrt.c:3
float __fres(float)
double sin(double)
double asin(double)
Definition w_asin.c:3
double exp(double)
Definition w_exp.c:3
float ceilf(float num)
Definition math.h:28
float i_sinf(float x)
Definition math.h:120
float atan2f(float y, float x)
Definition math.h:116
double fabsf2(float f)
Definition math.h:49