1 | #ifndef wren_math_h |
2 | #define wren_math_h |
3 | |
4 | #include <math.h> |
5 | #include <stdint.h> |
6 | |
7 | // A union to let us reinterpret a double as raw bits and back. |
8 | typedef union |
9 | { |
10 | uint64_t bits64; |
11 | uint32_t bits32[2]; |
12 | double num; |
13 | } WrenDoubleBits; |
14 | |
15 | #define WREN_DOUBLE_QNAN_POS_MIN_BITS (UINT64_C(0x7FF8000000000000)) |
16 | #define WREN_DOUBLE_QNAN_POS_MAX_BITS (UINT64_C(0x7FFFFFFFFFFFFFFF)) |
17 | |
18 | #define WREN_DOUBLE_NAN (wrenDoubleFromBits(WREN_DOUBLE_QNAN_POS_MIN_BITS)) |
19 | |
20 | static inline double wrenDoubleFromBits(uint64_t bits) |
21 | { |
22 | WrenDoubleBits data; |
23 | data.bits64 = bits; |
24 | return data.num; |
25 | } |
26 | |
27 | static inline uint64_t wrenDoubleToBits(double num) |
28 | { |
29 | WrenDoubleBits data; |
30 | data.num = num; |
31 | return data.bits64; |
32 | } |
33 | |
34 | #endif |
35 | |