Files
tp/include/MSL_C/math.h
T

85 lines
1.6 KiB
C
Raw Normal View History

2022-03-19 23:44:14 -04:00
#ifndef MSL_MATH_H_
#define MSL_MATH_H_
2022-03-20 00:01:24 -04:00
#include "MSL_C/MSL_Common/Src/float.h"
2022-03-19 23:44:14 -04:00
#define NAN (*(float*) __float_nan)
#define HUGE_VALF (*(float*) __float_huge)
#define M_PI 3.14159265358979323846f
#define DEG_TO_RAD(degrees) (degrees * (M_PI / 180.0f))
2022-04-24 04:02:50 -07:00
#ifdef __cplusplus
2022-03-19 23:44:14 -04:00
extern "C" {
2022-04-24 04:02:50 -07:00
#endif
2022-03-19 23:44:14 -04:00
2022-04-24 04:02:50 -07:00
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);
2022-03-19 23:44:14 -04:00
}
2022-04-24 04:02:50 -07:00
inline double fabsf2(float f) {
2022-03-19 23:44:14 -04:00
return __fabsf(f);
}
2022-04-24 04:02:50 -07:00
inline float fabsf(float f) {
2022-03-19 23:44:14 -04:00
return fabsf2(f);
}
2022-04-24 04:02:50 -07:00
double floor(double);
double fmod(double, double);
inline float fmodf(float f1, float f2) {
2022-03-19 23:44:14 -04:00
return fmod(f1, f2);
}
2022-04-24 04:02:50 -07:00
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);
2022-03-19 23:44:14 -04:00
2022-04-24 04:02:50 -07:00
inline double sqrt_step(double tmpd, float mag) {
2022-03-19 23:44:14 -04:00
return tmpd * 0.5 * (3.0 - mag * (tmpd * tmpd));
}
2022-04-24 04:02:50 -07:00
inline float sqrtf(float mag) {
2022-03-19 23:44:14 -04:00
if (mag > 0.0f) {
2022-04-24 04:02:50 -07:00
double tmpd = __frsqrte(mag);
2022-03-19 23:44:14 -04:00
tmpd = sqrt_step(tmpd, mag);
tmpd = sqrt_step(tmpd, mag);
tmpd = sqrt_step(tmpd, mag);
return mag * tmpd;
} else if (mag < 0.0) {
return NAN;
2022-03-19 23:44:14 -04:00
} else if (fpclassify(mag) == 1) {
return NAN;
2022-03-19 23:44:14 -04:00
} else {
return mag;
}
}
2022-04-24 04:02:50 -07:00
2022-05-28 03:49:55 -07:00
inline float atan2f(float y, float x) {
2023-01-02 21:28:46 -08:00
return (float)atan2(y, x);
2022-05-28 03:49:55 -07:00
}
2022-04-24 04:02:50 -07:00
#ifdef __cplusplus
};
#endif
2022-03-19 23:44:14 -04:00
#endif