summaryrefslogtreecommitdiff
path: root/src/utils/fpmath.h
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-23 09:58:48 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-23 09:58:48 +0000
commita3b7632e61981a730a8883a13f36f19be75647f1 (patch)
tree07ec4da268fb7e7f9aa2ddc20c5379e7f5982003 /src/utils/fpmath.h
parent1f0c609def5cff6b7bc16ddeefafb1654b11cb71 (diff)
downloadlibcss-a3b7632e61981a730a8883a13f36f19be75647f1.tar.gz
libcss-a3b7632e61981a730a8883a13f36f19be75647f1.tar.bz2
All numerical values are represented in 22:10 fixed point.
svn path=/trunk/libcss/; revision=5762
Diffstat (limited to 'src/utils/fpmath.h')
-rw-r--r--src/utils/fpmath.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/utils/fpmath.h b/src/utils/fpmath.h
new file mode 100644
index 0000000..edf6471
--- /dev/null
+++ b/src/utils/fpmath.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef css_utils_fpmath_h_
+#define css_utils_fpmath_h_
+
+#include <stdint.h>
+
+/* 22:10 fixed point math */
+typedef int32_t fixed;
+
+/* Add two fixed point values */
+#define FADD(a, b) ((a) + (b))
+/* Subtract two fixed point values */
+#define FSUB(a, b) ((a) - (b))
+/* Multiply two fixed point values */
+#define FMUL(a, b) (((a) * (b)) >> 10)
+/* Divide two fixed point values */
+#define FDIV(a, b) (((a) << 10) / (b))
+
+/* Add an integer to a fixed point value */
+#define FADDI(a, b) ((a) + ((b) << 10))
+/* Subtract an integer from a fixed point value */
+#define FSUBI(a, b) ((a) - ((b) << 10))
+/* Multiply a fixed point value by an integer */
+#define FMULI(a, b) ((a) * (b))
+/* Divide a fixed point value by an integer */
+#define FDIVI(a, b) ((a) / (b))
+
+/* Convert a floating point value to fixed point */
+#define FLTTOFIX(a) ((fixed) ((a) * (float) (1 << 10)))
+/* Convert a fixed point value to floating point */
+#define FIXTOFLT(a) ((float) (a) / (float) (1 << 10))
+
+/* Convert an integer to a fixed point value */
+#define INTTOFIX(a) ((a) << 10)
+/* Convert a fixed point value to an integer */
+#define FIXTOINT(a) ((a) >> 10)
+
+#endif
+