agi.foundation
(agi.foundation.core-2021r1.jar)

## Class FloatingPointComparison

• ```public final class FloatingPointComparison
extends Object```
Contains methods for comparing floating point numbers.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static double` `cubeRoot(double x)`
Computes the real-valued cube root if a given number.
`static double` ```divideRoundTripIsGreaterOrEqual(double dividend, double divisor)```
Divides a dividend by a divisor such that if the quotient is later multiplied by the divisor the result is greater than or equal to the dividend.
`static double` ```divideRoundTripIsLessOrEqual(double dividend, double divisor)```
Divides a dividend by a divisor such that if the quotient is later multiplied by the divisor the result is less than or equal to the dividend.
`static boolean` ```equalsSignificantDigits(double x, double y, int significantDigits)```
Compares two numbers up to the specified number of significant digits.
`static boolean` ```equalsSignificantDigits(double x, double y, int significantDigits, int maxDigitDifference)```
Compares two numbers up to the specified number of significant digits.
`static boolean` ```equalsSignificantDigitsOrAbsoluteError(double x, double y, int significantDigits, double absoluteError)```
Compares two numbers up to the specified number of significant digits or by their absolute error.
`static int` `getVariableExponent(double var)`
Returns the order N of the given variable of the form: var * 10^-(N+1) is less than 0.0
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### equalsSignificantDigits

```public static boolean equalsSignificantDigits(double x,
double y,
int significantDigits)```
Compares two numbers up to the specified number of significant digits.
Parameters:
`x` - The first number to compare.
`y` - The second number to compare
`significantDigits` - The number of significant digits to consider in the comparison.
Returns:
`true` if the nth significant digit of the two numbers differ by no more than 1 and all preceding significant digits are equal; otherwise `false`.
• #### equalsSignificantDigits

```public static boolean equalsSignificantDigits(double x,
double y,
int significantDigits,
int maxDigitDifference)```
Compares two numbers up to the specified number of significant digits.
Parameters:
`x` - The first number to compare.
`y` - The second number to compare
`significantDigits` - The number of significant digits to consider in the comparison.
`maxDigitDifference` - The maximum difference in the last significant digit.
Returns:
`true` if the nth significant digit of the two numbers differ by no more than 1 and all preceding significant digits are equal; otherwise `false`.
• #### equalsSignificantDigitsOrAbsoluteError

```public static boolean equalsSignificantDigitsOrAbsoluteError(double x,
double y,
int significantDigits,
double absoluteError)```
Compares two numbers up to the specified number of significant digits or by their absolute error.
Parameters:
`x` - The first number to compare.
`y` - The second number to compare
`significantDigits` - The number of significant digits to consider in the comparison.
`absoluteError` - The maximum allowable difference between x and y.
Returns:
`true` if the nth significant digit of the two numbers differ by no more than 1 and all preceding significant digits are equal, or if the difference between the two numbers is less than the absolute error specified; otherwise `false`.
• #### divideRoundTripIsGreaterOrEqual

```public static double divideRoundTripIsGreaterOrEqual(double dividend,
double divisor)```
Divides a dividend by a divisor such that if the quotient is later multiplied by the divisor the result is greater than or equal to the dividend.

If floating point numbers were infinitely precise, this method would be unnecessary. Since they're not, this method allows you to have control over how the error falls. For example, imagine that you have a floating point number that represents the minimum value allowed as input to a function. You want to express that minimum value in a different set of units such that the user can pass the minimum value to the function in that different set of units. By using this method to do the conversion to the alternate set of units, you guarantee that upon converting that value back to the original set of units the value will be greater than or equal to the original minimum value. Using a normal division might cause the value to actually be less than the minimum upon doing the round-trip conversion, which would likely cause the function to fail.

Parameters:
`dividend` - The dividend.
`divisor` - The divisor.
Returns:
The quotient.
• #### divideRoundTripIsLessOrEqual

```public static double divideRoundTripIsLessOrEqual(double dividend,
double divisor)```
Divides a dividend by a divisor such that if the quotient is later multiplied by the divisor the result is less than or equal to the dividend.

If floating point numbers were infinitely precise, this method would be unnecessary. Since they're not, this method allows you to have control over how the error falls. For example, imagine that you have a floating point number that represents the maximum value allowed as input to a function. You want to express that maximum value in a different set of units such that the user can pass the maximum value to the function in that different set of units. By using this method to do the conversion to the alternate set of units, you guarantee that upon converting that value back to the original set of units the value will be less than or equal to the original maximum value. Using a normal division might cause the value to actually be greater than the maximum upon doing the round-trip conversion, which would likely cause the function to fail.

Parameters:
`dividend` - The dividend.
`divisor` - The divisor.
Returns:
The quotient.
• #### getVariableExponent

`public static int getVariableExponent(double var)`
Returns the order N of the given variable of the form: var * 10^-(N+1) is less than 0.0
Parameters:
`var` - The variable
Returns:
The order of the variable
• #### cubeRoot

`public static double cubeRoot(double x)`
Computes the real-valued cube root if a given number. The cube root of a negative value is the negative of the cube root of that value's magnitude.
Parameters:
`x` - The value for which to compute the cube root.
Returns:
The cube root.