Additional mathematical functions and determines the parameters of the floating point representation.
More...
#include <math_util.h>
|
| static int | radix () noexcept |
| | Gets the machine radix used by floating-point numbers. More...
|
| |
| static double | machine_precision () noexcept |
| | Gets the largest positive value which, when added to 1.0, yields 0. More...
|
| |
| static double | default_numerical_precision () noexcept |
| | Gets the typical meaningful precision for numerical calculations. More...
|
| |
| static bool | equal (double left, double right) noexcept |
| | Compares two floating-point numbers for relative equality using the default numerical precision. More...
|
| |
| static bool | equal (double left, double right, double precision) noexcept |
| | Compares two floating-point numbers for relative equality. More...
|
| |
Additional mathematical functions and determines the parameters of the floating point representation.
References:
- William Cody, Algorithm 665: MACHAR, a subroutine to dynamically determine machine parameters, ACM Transactions on Mathematical Software, Volume 14, Number 4, December 1988, pages 303-311.
- Didier H. Besset, Object-Oriented Implementation of Numerical Methods An Introduction with Smalltalk, Morgan Kaufmann, November 2000.
◆ MathHelper()
| hgps::core::MathHelper::MathHelper |
( |
| ) |
|
|
delete |
◆ default_numerical_precision()
| double hgps::core::MathHelper::default_numerical_precision |
( |
| ) |
|
|
staticnoexcept |
Gets the typical meaningful precision for numerical calculations.
- Returns
- The default precision for numerical calculations
◆ equal() [1/2]
| bool hgps::core::MathHelper::equal |
( |
double |
left, |
|
|
double |
right |
|
) |
| |
|
staticnoexcept |
Compares two floating-point numbers for relative equality using the default numerical precision.
- Parameters
-
| left | The left double to compare. |
| right | The right double to compare. |
- Returns
- true if the number are equal, otherwise. false
◆ equal() [2/2]
| bool hgps::core::MathHelper::equal |
( |
double |
left, |
|
|
double |
right, |
|
|
double |
precision |
|
) |
| |
|
staticnoexcept |
Compares two floating-point numbers for relative equality.
Since the floating-point representation is keeping a constant relative precision, comparison must be made using relative error.
Let a and b be the two numbers to be compared, we build the following expression:
x = |a - b| / max(|a|, |b|)
The two numbers can be considered equal if x is smaller than a given number xmax. If the denominator of the fraction on the above equation is less than xmax, than the two numbers can be considered as being equal. For lack of information on how the numbers a and b have been obtained, one uses for xmax the DefaultNumericalPrecision. If one can determine the precision of each number, then this relative equality method can be used.
- Parameters
-
| left | The left double to compare. |
| right | The right double to compare. |
| precision | The comparison precision. |
- Returns
- true if the number are equal, otherwise. false
◆ machine_precision()
| double hgps::core::MathHelper::machine_precision |
( |
| ) |
|
|
staticnoexcept |
Gets the largest positive value which, when added to 1.0, yields 0.
- Returns
- The machine precision value
◆ radix()
| int hgps::core::MathHelper::radix |
( |
| ) |
|
|
staticnoexcept |
Gets the machine radix used by floating-point numbers.
- Returns
- The machine radix value
The documentation for this class was generated from the following files: