12 #include "../stdafx.h" 15 #include "../safeguards.h" 28 if (a == 0 || b == 0)
return 0;
29 if (a == 1 || a == b)
return b;
61 int random_like = ((a + b) * (a - b)) % b;
63 int remainder = a % b;
66 if (
abs(random_like) <
abs(remainder)) {
67 ret += ((a < 0) ^ (b < 0)) ? -1 : 1;
82 uint32 bit = 1UL << 30;
85 while (bit > num) bit >>= 2;
88 if (num >= res + bit) {
90 res = (res >> 1) + bit;
int DivideApprox(int a, int b)
Deterministic approximate division.
int LeastCommonMultiple(int a, int b)
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multip...
int GreatestCommonDivisor(int a, int b)
Compute greatest common divisor (gcd) of a and b.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
uint32 IntSqrt(uint32 num)
Compute the integer square root.