Free Electron
math_defs.h
1 #ifndef AL_MATH_DEFS_H
2 #define AL_MATH_DEFS_H
3 
4 #include <math.h>
5 #ifdef HAVE_FLOAT_H
6 #include <float.h>
7 #endif
8 
9 #ifndef M_PI
10 #define M_PI (3.14159265358979323846)
11 #endif
12 
13 #define F_PI (3.14159265358979323846f)
14 #define F_PI_2 (1.57079632679489661923f)
15 #define F_TAU (6.28318530717958647692f)
16 
17 #ifndef FLT_EPSILON
18 #define FLT_EPSILON (1.19209290e-07f)
19 #endif
20 
21 #define SQRT_2 1.41421356237309504880
22 #define SQRT_3 1.73205080756887719318
23 
24 #define SQRTF_2 1.41421356237309504880f
25 #define SQRTF_3 1.73205080756887719318f
26 
27 #ifndef HUGE_VALF
28 static const union msvc_inf_hack {
29  unsigned char b[4];
30  float f;
31 } msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
32 #define HUGE_VALF (msvc_inf_union.f)
33 #endif
34 
35 #ifndef HAVE_LOG2F
36 static inline float log2f(float f)
37 {
38  return logf(f) / logf(2.0f);
39 }
40 #endif
41 
42 #ifndef HAVE_CBRTF
43 static inline float cbrtf(float f)
44 {
45  return powf(f, 1.0f/3.0f);
46 }
47 #endif
48 
49 #ifndef HAVE_COPYSIGNF
50 static inline float copysignf(float x, float y)
51 {
52  union {
53  float f;
54  unsigned int u;
55  } ux = { x }, uy = { y };
56  ux.u &= 0x7fffffffu;
57  ux.u |= (uy.u&0x80000000u);
58  return ux.f;
59 }
60 #endif
61 
62 #define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0))
63 #define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI))
64 
65 #endif /* AL_MATH_DEFS_H */