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

Parsing floating point numbers is inaccurate #1573

Closed
gfwilliams opened this issue Nov 29, 2018 · 2 comments
Closed

Parsing floating point numbers is inaccurate #1573

gfwilliams opened this issue Nov 29, 2018 · 2 comments

Comments

@gfwilliams
Copy link
Member

http://forum.espruino.com/conversations/328291/#comment14522349

//Espruino
>console.log(new Uint8Array(new Float64Array([0.95, 1-0.05]).buffer))
new Uint8Array([
103, 102, 102, 102, 102, 102, 238, 63, 
102, 102, 102, 102, 102, 102, 238, 63])

// Node.js
>console.log(new Uint8Array(new Float64Array([0.95, 1-0.05]).buffer))
new Uint8Array([
102, 102, 102, 102, 102, 102, 238, 63, 
102, 102, 102, 102, 102, 102, 238, 63])

Need to look at whether there's an easy fix for this.

@gfwilliams
Copy link
Member Author

Note that this is based on 1-0.05 == 0.95 => false in Espruino

But 0.3 == 0.1+0.1+0.1 => false in Node.js and Chrome so this is never going to be a complete fix.

@gfwilliams
Copy link
Member Author

Nobody seems too bothered - floats aren't 100% accurate anyway

@gfwilliams gfwilliams closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2024
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

No branches or pull requests

1 participant