Double#compare(double, double) won't do.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static int | Returns: negative, 0, or positive according to the standard Excel comparison
of values a and b.This class attempts to reproduce Excel's behaviour for comparing numbers. |
| private static int | Returns: usuallyisNegative ? -1 : +1both values are either negative or positive. This parameter affects the sign of the comparison result isNegative)Usually any normal number is greater (in magnitude) than any subnormal number. |
| private static int | compareSubnormalNumbers(long fracA, long fracB, boolean isNegative)
If both numbers are subnormal, Excel seems to use standard comparison rules |
| private static String |
| NumberComparer | back to summary |
|---|---|
| public NumberComparer() | |
| compare | back to summary |
|---|---|
| public static int compare(double a, double b) This class attempts to reproduce Excel's behaviour for comparing numbers. Results are
mostly the same as those from
In Excel formula evaluation, expressions like "(0.06-0.01)=0.05" evaluate to "TRUE" even
though the equivalent java expression is
Note - Excel also gives special treatment to expressions like "0.06-0.01-0.05" which
evaluates to "0" (in java, rounding anomalies give a result of 6.9E-18). The special
behaviour here is for different reasons to the example above: If the last operator in a
cell formula is '+' or '-' and the result is less than 250 times smaller than
first operand, the result is rounded to zero.
Needless to say, the two rules are not consistent and it is relatively easy to find
examples that satisfy
| |
| compareAcrossSubnormalThreshold | back to summary |
|---|---|
| private static int compareAcrossSubnormalThreshold(long normalRawBitsA, long subnormalRawBitsB, boolean isNegative) Usually any normal number is greater (in magnitude) than any subnormal number. However there are some anomalous cases around the threshold where Excel produces screwy results
| |
| compareSubnormalNumbers | back to summary |
|---|---|
| private static int compareSubnormalNumbers(long fracA, long fracB, boolean isNegative) If both numbers are subnormal, Excel seems to use standard comparison rules | |
| toHex | back to summary |
|---|---|
| private static String toHex(double a) for formatting double values in error messages | |