Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.Math is missing nextUp, nextDown, nextAfter emulation #9977

Closed
niloc132 opened this issue Jul 10, 2024 · 0 comments · Fixed by #9978
Closed

java.lang.Math is missing nextUp, nextDown, nextAfter emulation #9977

niloc132 opened this issue Jul 10, 2024 · 0 comments · Fixed by #9978

Comments

@niloc132
Copy link
Contributor

niloc132 commented Jul 10, 2024

Historically these were deliberately omitted, but were added in Java 6:

// public static double nextAfter(double start, double direction)
// public static float nextAfter(float start, float direction)
// public static double nextUp(double start) {
// return nextAfter(start, 1.0d);
// }
// public static float nextUp(float start) {
// return nextAfter(start,1.0f);
// }

The addition of Double.doubleToLongBits/longBitsToDouble and Float.floatToIntBits/intBitsToFloat appears to overcome the browser limitations indicated.

Note that this comment block is misleading - nextUp should pass INFINITY values as the "direction" parameter according to the javadoc - passing 1.0 and -1.0 will result in incorrect values even in the JVM impl.

Java 8 added the nextDown method as well.

These links are only for the double variants, but each has a float overload as well:
https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#nextAfter-double-double-
https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#nextUp-double-
https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#nextDown-double-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant