Math utility class. Note that the test() routine should return true for all implementations.
More...
|
| int | round_int (double x) |
| | Round to nearest integer. This routine does fast rounding to the nearest integer. In the case (k + 0.5 for any integer k) we round up to k+1, and in all other instances we should return the nearest integer. Thus, { -1.5, -0.5, 0.5, 1.5 } is rounded to { -1, 0, 1, 2 }. It preserves the property that round(k) - round(k-1) = 1 for all doubles k.
|
| |
| int | round_int (float x) |
| | Round to nearest integer.
|
| |
| int | truncate_int (double x) |
| | Truncate to nearest integer. This routine does fast truncation to an integer. It should simply drop the fractional portion of the floating point number.
|
| |
| int64_t | abs (int64_t a) |
| |
| unsigned | bitcount (unsigned v) |
| |
| void | hack () |
| |
| template<typename FloatT > |
| bool | FloatEquals (FloatT f1, FloatT f2, FloatT maxDelta) |
| |
| template<typename T , std::enable_if_t< std::is_floating_point< T >::value, bool > = true> |
| T | RoundF (const T value, const T multiple) |
| | Round a floating point number to nearest multiple.
|
| |
Math utility class. Note that the test() routine should return true for all implementations.
See http://ldesoras.free.fr/doc/articles/rounding_en.pdf for an explanation of the technique used on x86.
◆ abs()
◆ bitcount()
| unsigned MathUtils::bitcount |
( |
unsigned |
v | ) |
|
|
inline |
◆ FloatEquals()
template<typename FloatT >
| bool MathUtils::FloatEquals |
( |
FloatT |
f1, |
|
|
FloatT |
f2, |
|
|
FloatT |
maxDelta |
|
) |
| |
|
inline |
Compare two floating-point numbers for equality and regard them as equal if their difference is below a given threshold.
It is usually not useful to compare float numbers for equality with the standard operator== since very close numbers might have different representations.
◆ hack()
◆ round_int() [1/2]
| int MathUtils::round_int |
( |
double |
x | ) |
|
|
inline |
Round to nearest integer. This routine does fast rounding to the nearest integer. In the case (k + 0.5 for any integer k) we round up to k+1, and in all other instances we should return the nearest integer. Thus, { -1.5, -0.5, 0.5, 1.5 } is rounded to { -1, 0, 1, 2 }. It preserves the property that round(k) - round(k-1) = 1 for all doubles k.
Make sure MathUtils::test() returns true for each implementation.
- See also
- truncate_int, test
◆ round_int() [2/2]
| int MathUtils::round_int |
( |
float |
x | ) |
|
|
inline |
◆ RoundF()
template<typename T , std::enable_if_t< std::is_floating_point< T >
::value,
bool > = true>
| T MathUtils::RoundF |
( |
const T |
value, |
|
|
const T |
multiple |
|
) |
| |
|
inline |
Round a floating point number to nearest multiple.
- Parameters
-
| value | The value to round |
| multiple | The multiple |
- Returns
- The rounded value
◆ truncate_int()
| int MathUtils::truncate_int |
( |
double |
x | ) |
|
|
inline |
Truncate to nearest integer. This routine does fast truncation to an integer. It should simply drop the fractional portion of the floating point number.
Make sure MathUtils::test() returns true for each implementation.
- See also
- round_int, test