summaryrefslogtreecommitdiff
path: root/common/math_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/math_util.c')
-rw-r--r--common/math_util.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/common/math_util.c b/common/math_util.c
index 22f5872267..e80d6a9888 100644
--- a/common/math_util.c
+++ b/common/math_util.c
@@ -272,3 +272,11 @@ void rotate_inv(const intv3_t v, const mat33_fp_t R, intv3_t res)
res[1] = FP_TO_INT(fp_div(t[1], deter));
res[2] = FP_TO_INT(fp_div(t[2], deter));
}
+
+/* division that round to the nearest integer */
+int round_divide(int64_t dividend, int divisor)
+{
+ return (dividend > 0) ^ (divisor > 0) ?
+ (dividend - divisor / 2) / divisor :
+ (dividend + divisor / 2) / divisor;
+}