summaryrefslogtreecommitdiff
path: root/include/MSL_C/math.h
blob: 0bae081bf72a07765b49649667a200fa7932d47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MSL_MATH_H_
#define MSL_MATH_H_

#include "MSL_C/MSL_Common/Src/float.h"
#include "dolphin/types.h"

#define M_PI 3.14159265358979323846f

#define DEG_TO_RAD(degrees) (degrees * (M_PI / 180.0f))

#ifdef __cplusplus
extern "C" {
#endif

int abs(int);
double acos(double);
float acosf(float);
double asin(double);
double atan(double);
double atan2(double, double);
double ceil(double);
double copysign(double, double);
double cos(double);
float cosf(float);
double exp(double);

extern float __fabsf(float);
inline double fabs(double f) {
    return __fabs(f);
}
inline double fabsf2(float f) {
    return __fabsf(f);
}
inline float fabsf(float f) {
    return fabsf2(f);
}

double floor(double);
double fmod(double, double);
inline float fmodf(float f1, float f2) {
    return fmod(f1, f2);
}

double frexp(double, int*);
double ldexp(double, int);
double modf(double, double*);
double pow(double, double);
double sin(double);
float sinf(float);
double sqrt(double);
double tan(double);
float tanf(float);

extern float __float_nan[4];
extern float __float_epsilon[4];
extern float __float_max[4];

inline double sqrt_step(double tmpd, float mag) {
    return tmpd * 0.5 * (3.0 - mag * (tmpd * tmpd));
}

inline float sqrtf(float mag) {
    if (mag > 0.0f) {
        double tmpd = __frsqrte(mag);
        tmpd = sqrt_step(tmpd, mag);
        tmpd = sqrt_step(tmpd, mag);
        tmpd = sqrt_step(tmpd, mag);
        return mag * tmpd;
    } else if (mag < 0.0) {
        return __float_nan[0];
    } else if (fpclassify(mag) == 1) {
        return __float_nan[0];
    } else {
        return mag;
    }
}

inline float atan2f(float y, float x) {
    return (f32)atan2(y, x);
}

#ifdef __cplusplus
};
#endif

#endif