use the fast double->int conversion in 3dgfx.c
[dosdemo] / src / util.h
diff --git a/src/util.h b/src/util.h
new file mode 100644 (file)
index 0000000..eb3773d
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include "inttypes.h"
+
+#ifdef __GNUC__
+#define INLINE __inline
+
+#elif defined(__WATCOMC__)
+#define INLINE __inline
+
+#else
+#define INLINE
+#endif
+
+/* fast conversion of double -> 32bit int
+ * for details see:
+ *  - http://chrishecker.com/images/f/fb/Gdmfp.pdf
+ *  - http://stereopsis.com/FPU.html#convert
+ */
+static INLINE int32_t cround64(double val)
+{
+       val += 6755399441055744.0;
+       return *(int32_t*)&val;
+}
+
+#endif /* UTIL_H_ */