class
#include <bn_rule_of_three_approximation.h>
rule_of_three_approximation Approximates a rule of three cross-multiplication (x = (value * multiplier) / divisor).
rule_
See https://en.wikipedia.org/wiki/Cross-multiplication#Rule_
Constructors, destructors, conversion operators
- rule_of_three_approximation(int divisor, int multiplier) constexpr
- Constructor.
Public functions
- auto calculate(unsigned value) const -> unsigned constexpr
- Returns an approximation of (value * multiplier) / divisor, casting the value to uint64_t to try to avoid integer overflow.
- auto unsafe_calculate(unsigned value) const -> unsigned constexpr
- Returns an approximation of (value * multiplier) / divisor, without trying to avoid integer overflow.
- auto calculate(int value) const -> int constexpr
- Returns an approximation of (value * multiplier) / divisor, casting the value to int64_t to try to avoid integer overflow.
- auto unsafe_calculate(int value) const -> int constexpr
- Returns an approximation of (value * multiplier) / divisor, without trying to avoid integer overflow.
-
template<int Precision>auto calculate(fixed_
t<Precision> value) const -> fixed_ t<Precision> constexpr - Returns an approximation of (value * multiplier) / divisor, casting the value to int64_t to try to avoid integer overflow.
-
template<int Precision>auto unsafe_calculate(fixed_
t<Precision> value) const -> fixed_ t<Precision> constexpr - Returns an approximation of (value * multiplier) / divisor, without trying to avoid integer overflow.
Function documentation
bn:: rule_of_three_approximation:: rule_of_three_approximation(int divisor,
int multiplier) constexpr
Constructor.
Parameters | |
---|---|
divisor | Valid divisor (> 0). |
multiplier | Valid multiplier (> 0). |