aboutsummaryrefslogtreecommitdiff
path: root/common/math.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/math.h')
-rw-r--r--common/math.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/common/math.h b/common/math.h
index 7b2ec6060e..2c62fce6d5 100644
--- a/common/math.h
+++ b/common/math.h
@@ -107,6 +107,20 @@ inline int intLog2(uint32 v) {
}
#endif
+// Round a number towards zero
+// Input and Output type can be different
+template<class InputT, class OutputT>
+inline OutputT trunc(InputT x) {
+ return (x > 0) ? floor(x) : ceil(x);
+}
+
+// Round a number towards zero
+// Input and Output type are the same
+template<class T>
+inline T trunc(T x) {
+ return trunc<T,T>(x);
+}
+
// Convert radians to degrees
// Input and Output type can be different
// Upconvert everything to floats