OpenTTD
|
Math functions. More...
Go to the source code of this file.
Functions | |
int | LeastCommonMultiple (int a, int b) |
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multiple of both a and b. | |
int | GreatestCommonDivisor (int a, int b) |
Compute greatest common divisor (gcd) of a and b. | |
int | DivideApprox (int a, int b) |
Deterministic approximate division. | |
uint32 | IntSqrt (uint32 num) |
Compute the integer square root. |
Math functions.
Definition in file math_func.cpp.
int DivideApprox | ( | int | a, |
int | b | ||
) |
Deterministic approximate division.
Cancels out division errors stemming from the integer nature of the division over multiple runs.
a | Dividend. |
b | Divisor. |
Definition at line 59 of file math_func.cpp.
References abs().
Referenced by StationViewWindow::BuildCargoList(), and StationViewWindow::EstimateDestinations().
int GreatestCommonDivisor | ( | int | a, |
int | b | ||
) |
Compute greatest common divisor (gcd) of a and b.
a | First number. |
b | second number. |
Definition at line 41 of file math_func.cpp.
Referenced by LeastCommonMultiple().
uint32 IntSqrt | ( | uint32 | num | ) |
Compute the integer square root.
num | Radicand. |
Definition at line 79 of file math_func.cpp.
Referenced by CanalMaintenanceCost(), RailMaintenanceCost(), RoadMaintenanceCost(), SignalMaintenanceCost(), and StationMaintenanceCost().
int LeastCommonMultiple | ( | int | a, |
int | b | ||
) |
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multiple of both a and b.
a | First number. |
b | second number. |
Definition at line 26 of file math_func.cpp.
References GreatestCommonDivisor().
Referenced by NWidgetStacked::SetupSmallestSize(), NWidgetHorizontal::SetupSmallestSize(), NWidgetVertical::SetupSmallestSize(), and NWidgetNewGRFDisplay::SetupSmallestSize().