Skip to content

Conversation

@robinschmid
Copy link
Member

Cleaned up the changes that I tried in precision class.

I checked and Float.NaN and Float.POSITIVE_INFINITY are perfectly converted to Double so that no extra checks are required.

Double.compare(a, b) == 0 already covers the case where both values are NaN so I removed the extra checks.

Added a check for the Double.isInfinite(diff) to capture number overflow.

// Math.floor always rounds to next smaller number so negative values will be like -3.1 -> -4
// +1 as we are using floor and in both positive and negative exponents we need +1
final double max = Math.max(Math.abs(a), Math.abs(b));
final double scaledSignificance = Math.pow(10, sigDigits * -1d) * max;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pow is not needed. The old version does pow(log10(pow)) the new version just does pow(log10)

}
final double diff = Math.abs(a - b);
// if one is infinite or if number overflow
if (Double.isInfinite(diff)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to handle number overflow

* NaN, false if only one is NaN
*/
public static boolean equalRelativeSignificance(final double a, final double b,
final double relativeError) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the methods available in apache commons math Precision.
They have one that just uses relative value precision and maybe thats actually fine? Then we dont need all the fancy log10, floor, pow10. Maybe forcing it into the decimal system with pow10 is actually bad because we still get all the flaoting point inaccuracies like we want 10 but it may be 9.99999.

Only issue in apache version is that it returns false if both values are NaN.
So better to reimplement here.

to check default float accuracy we could either use 1E-5 or 5E-6 for checks

public static boolean equalRelativeSignificance(final double a, final double b,
final double relativeError) {
// equal or both are NaN
if (Double.compare(a, b) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a = positive and b = negative infinity will not be equal, or? they may cause number overflow later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked. This this comes down to max and a-b are both INFINITY and devided this is NaN and NaN is always false when compared to any other number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so test result is correct

@SteffenHeu SteffenHeu merged commit 768c9f7 into mzmine:master Nov 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants