Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-09-18 06:14:58 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-09-18 06:18:50 +0300
commit990515a5a72692e7ee93c68d393352cad375171c (patch)
tree1e653d282b8af1c95da7560ce927132e9c4556e2
parent9134529b9eb9401470eb51d1cfc0d91a2ad2c109 (diff)
Math Lib: add divide_floor_i
Integer division that floors on negative output (like Python's).
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 6574c001a23..5ae2b1a70a7 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -194,6 +194,17 @@ MINLINE int divide_round_i(int a, int b)
}
/**
+ * Integer division that floors negative result.
+ * \note This works like Python's int division.
+ */
+MINLINE int divide_floor_i(int a, int b)
+{
+ int d = a / b;
+ int r = a % b; /* Optimizes into a single division. */
+ return r ? d - ((a < 0) ^ (b < 0)) : d;
+}
+
+/**
* modulo that handles negative numbers, works the same as Python's.
*/
MINLINE int mod_i(int i, int n)