Math Lib: add divide_floor_i
Integer division that floors on negative output (like Python's).
This commit is contained in:
@@ -193,6 +193,17 @@ MINLINE int divide_round_i(int a, int b)
|
||||
return (2 * a + b) / (2 * 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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user