58#ifndef __LIBDRAGON_FMATH_H
59#define __LIBDRAGON_FMATH_H
73#define BITCAST_F2I(f) ({ int32_t i; memcpy(&i, &f, 4); i; })
79#define BITCAST_I2F(i) ({ float f; memcpy(&f, &i, 4); f; })
86static inline float fm_truncf(
float x) {
91 __asm (
"trunc.w.s %0,%1" :
"=f"(yint) :
"f"(x));
92 __asm (
"cvt.s.w %0,%1" :
"=f"(y) :
"f"(yint));
101static inline float fm_ceilf(
float x) {
103 __asm (
"ceil.w.s %0,%1" :
"=f"(yint) :
"f"(x));
104 __asm (
"cvt.s.w %0,%1" :
"=f"(y) :
"f"(yint));
113static inline float fm_floorf(
float x) {
114 float y = fm_truncf(x);
116 if (x < 0) y -= 1.0f;
127static inline float fm_fmodf(
float x,
float y) {
128 return x - fm_floorf(x * (1.0f / y)) * y;
188void fm_sincosf(
float x,
float *sin,
float *cos);
202#ifdef LIBDRAGON_FAST_MATH
203 #define truncf(x) fm_truncf(x)
204 #define floorf(x) fm_floorf(x)
205 #define ceilf(x) fm_ceilf(x)
214 #define fmodf(x, y) ((__builtin_constant_p(x) && __builtin_constant_p(y)) ? fmodf(x,y) : fm_fmodf(x,y))
215 #define sinf(x) (__builtin_constant_p(x) ? sinf(x) : fm_sinf(x))
216 #define cosf(x) (__builtin_constant_p(x) ? cosf(x) : fm_cosf(x))
217 #define sincosf(x,s,c) (__builtin_constant_p(x) ? sincosf(x,s,c) : fm_sincosf(x,s,c))
218 #define atan2f(y, x) ((__builtin_constant_p(x) && __builtin_constant_p(y)) ? atan2f(y, x) : fm_atan2f(y, x))
float fm_cosf(float x)
Faster version of cosf.
Definition fmath.c:52
float fm_atan2f(float y, float x)
Faster version of atan2f.
Definition fmath.c:67
float fm_sinf(float x)
Faster version of sinf.
Definition fmath.c:48
float fm_sinf_approx(float x, int approx)
Faster version of sinf, with tunable approximation level.
Definition fmath.c:39
void fm_sincosf(float x, float *sin, float *cos)
Faster version of sincosf.
Definition fmath.c:56