use the fast double->int conversion in 3dgfx.c
[dosdemo] / src / util.h
1 #ifndef UTIL_H_
2 #define UTIL_H_
3
4 #include "inttypes.h"
5
6 #ifdef __GNUC__
7 #define INLINE __inline
8
9 #elif defined(__WATCOMC__)
10 #define INLINE __inline
11
12 #else
13 #define INLINE
14 #endif
15
16 /* fast conversion of double -> 32bit int
17  * for details see:
18  *  - http://chrishecker.com/images/f/fb/Gdmfp.pdf
19  *  - http://stereopsis.com/FPU.html#convert
20  */
21 static INLINE int32_t cround64(double val)
22 {
23         val += 6755399441055744.0;
24         return *(int32_t*)&val;
25 }
26
27 #endif  /* UTIL_H_ */