-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
JS Backend: Long_fromNumber does not gracefully support NaN #1000
Comments
Note that fixing this may affect performance. Since such situation is quite rare, I doubt if it worth fixing. Also, did you try WasmGC backend? |
I think this case is not uncommon and can also happen rather "randomly" if some computation gets numerical instable. I really like that TeaVM is respecting the Java Language Specification to a high level, so it would be nice if this would be no exception. If you are scared of the extra isNaN check, then it would also be possible to wrap the BigInt constructor in a try { ... } catch { return BigInt(0) }. Unfortunately, I am running libgdx and cannot use WasmGC backend yet as I am also relying on the JS multithread feature. |
I have another opinion regarding this. Also, it's quite easy to fix on source code level: you can insert additional
No, TeaVM has a lots of places where it violates this. For example, TeaVM does not produce fair NPE, CCE or AAIOBE by default. Also, there are lots of edge cases like integer zero division, etc. GWT, j2cl, Kotlin/JS - all behave the same way, sacrificing some rare edge cases for performance.
No, this would kill performance even further. |
It's just complicated when these things occur in third party dependencies where you cannot add these extra checks. I know that integer zero division, NPE, CCE, ... are not handled correctly. But these are all cases which would throw in a real JVM and are widely considered as programmer's faults. It's very rare and very bad practice to rely on these exceptions for control flow. But here it's different. TeaVM throws although a JVM would not. |
When converting a double to a long the conversion may fail when the double is a NaN:
RangeError: The number NaN cannot be converted to a BigInt because it is not an integer at BigInt (<anonymous>) at Long_fromNumber
Expected behaviour: Return 0L instead.
The text was updated successfully, but these errors were encountered: