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

Open
gfwilliams opened this issue Nov 29, 2018 · 1 comment
Open

Parsing floating point numbers is inaccurate #1573

gfwilliams opened this issue Nov 29, 2018 · 1 comment

Comments

@gfwilliams
Copy link
Member

@gfwilliams gfwilliams commented Nov 29, 2018

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

@gfwilliams gfwilliams commented Nov 29, 2018

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.

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.