aboutsummaryrefslogtreecommitdiffstats
path: root/common/math_defs.h
blob: 1b24bec4c0a042182b60126993a9f2a17879918d (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
#ifndef AL_MATH_DEFS_H
#define AL_MATH_DEFS_H

#include <math.h>
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif

#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif

#define F_PI    (3.14159265358979323846f)
#define F_PI_2  (1.57079632679489661923f)
#define F_TAU   (6.28318530717958647692f)

#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif

#define SQRT_2 1.41421356237309504880
#define SQRT_3 1.73205080756887719318

#define SQRTF_2 1.41421356237309504880f
#define SQRTF_3 1.73205080756887719318f

#ifndef HUGE_VALF
static const union msvc_inf_hack {
    unsigned char b[4];
    float f;
} msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
#define HUGE_VALF (msvc_inf_union.f)
#endif

#ifndef HAVE_LOG2F
static inline float my_log2f(float f)
{
    return logf(f) / logf(2.0f);
}
#define log2f my_log2f
#endif

#ifndef HAVE_CBRTF
static inline float my_cbrtf(float f)
{
    return powf(f, 1.0f/3.0f);
}
#define cbrtf my_cbrtf
#endif

#ifndef HAVE_COPYSIGNF
static inline float my_copysignf(float x, float y)
{
    union {
        float f;
        unsigned int u;
    } ux = { x }, uy = { y };
    ux.u &= 0x7fffffffu;
    ux.u |= (uy.u&0x80000000u);
    return ux.f;
}
#define copysignf my_copysignf
#endif

#define DEG2RAD(x)  ((float)(x) * (float)(M_PI/180.0))
#define RAD2DEG(x)  ((float)(x) * (float)(180.0/M_PI))

#endif /* AL_MATH_DEFS_H */