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
Emulator: Math.ceil(Math.sqrt(9)) isn't 3 #2262
Comments
interesting, just tried in webide bangle2 emulator
|
I suspect this is related to #2245. Which version are you getting this strange result in? |
Yep, because it uses a different math lib than the nRF devices. |
Hmm, I noticed this some time ago, but forgot to report it, and only re-tested in it the emulator when I did remember. Seems to be fixed already though 🎉:
|
I realize this issue is closed, but I just experienced this issue in the emulator. @rigrig did you close this under the assumption that once the emulator was updated to at least 2v15.5 it would be fixed there? It seems like the emulator is running 2v18 now and the issue persists. Or is there a different repo where the issue is tracked for the emulator? It's not a blocker for me or anything, but wanted to point it out in case there was an assumption that it wasn't happening anymore. Right now the device and emulator behave differently in this regard. |
BTW, someone mentioned on Discord similar issue "Math.abs(Math.floor(14/8)-(14/8)) == 0.75 is false while it should be true" I tried also in emulator and it fails there in the same way. When printed it is rounded which makes it more confusing
In node.js it gives true. It was a bit surprising that Emulator has same floating point 'bugs' as the device but I guess it is a good thing after all? EDIT: when re-reading this issue it is not about generic floating point math precision issues but the |
Yups, I just assumed it would be fixed when the emulator was updated, but I was wrong :-( |
It's a tricky one - floating point maths is not exact, pretty much by definition. We're using standard IEEE-754 double precision floating point. If you did the same sum in C, I imagine you'd get the same answer. So I guess we can modify ceil to subtract 0.0000001 from the number before doing ceil, and modify floor to add the same, but it seems like a hack that may cause more problems than it solves |
I reopened it because it only affects the emulator: code working on the watch but breaking in the emulator seems a bit worrying. For example: I briefly added a workaround in Javascript for this code, and got rid of it when updating the firmware fixed this bug. I have no idea how the emulator works though: if it's just a completely different Javascript engine, that seems like a good enough explanation not to bother. |
Well, it does use the same engine, just compiled to JS - you can in fact step through it using Chrome debug tools. I just breakpointed on And breakpointing |
This only happens in the emulator
Expected:
3
(it is3
in node/Firefox console)(Maybe related to #2258?)
Emulator versions affected:
2v14.104
,2v18.1
(both Bangle.js 1 and Bangle.js 2)The text was updated successfully, but these errors were encountered: