OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
13 #include "../safeguards.h"
26 if (a == 0 || b == 0)
return 0;
27 if (a == 1 || a == b)
return b;
59 int random_like = ((a + b) * (a - b)) % b;
61 int remainder = a % b;
64 if (
abs(random_like) <
abs(remainder)) {
65 ret += ((a < 0) ^ (b < 0)) ? -1 : 1;
80 uint32 bit = 1UL << 30;
83 while (bit > num) bit >>= 2;
86 if (num >= res + bit) {
88 res = (res >> 1) + bit;
int DivideApprox(int a, int b)
Deterministic approximate division.
uint32 IntSqrt(uint32 num)
Compute the integer square root.
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.
int LeastCommonMultiple(int a, int b)
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multip...