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

Doubles are imprecise #99

Open
nico75005 opened this issue Mar 21, 2015 · 6 comments
Open

Doubles are imprecise #99

nico75005 opened this issue Mar 21, 2015 · 6 comments

Comments

@nico75005
Copy link

Hi, first thanks for this great library but I have a problem which actually seems well known with NSNumber.

When I evaluate a simple string through evaluateString like "1.2*6", the result is as expected 7.2 but when I call stringValue on this NSNumber(double), I get "7.199999999999999" or 7.1999999999999993 if I use doubleValue.

How can I do?

Thanks for your help

@nico75005
Copy link
Author

Well I just saw you added usesHighPrecisionEvaluation. It seems to fix the issue with stringValue but doesn't fix it with doubleValue

@nico75005 nico75005 changed the title Precision problem with stringValue in certain cases Precision problem with doubleValue in certain cases Mar 22, 2015
@davedelong davedelong changed the title Precision problem with doubleValue in certain cases Doubles are imprecise Sep 19, 2015
@davedelong
Copy link
Owner

What Every Computer Scientist Should Know About Floating-Point Arithmetic

Short of writing my own infinite-precision math framework, I'm not sure there's a way to "solve" this.

@JanX2
Copy link

JanX2 commented Sep 20, 2015

What about porting/wrapping one of the infinite-precision math framework written in C/C++?

I have been toying with the idea every since you started the Swift branch. Someone just needs to find the time. ;)

One of the candidates is MAPM.

@davedelong davedelong mentioned this issue Nov 18, 2016
@joshdistler
Copy link

I would love to see an infinite-precision implementation here. In testing, I'm seeing: 45.25 - 45 = 0.230000000000004. Any easy fix?

@davedelong
Copy link
Owner

No, this is not an easy fix. I'm waiting to implement this until Swift has a standardized "BigNum" library.

I've thought about making Expression generic with respect to its underlying number type, but so far there's too much up and down the stack that depends on having a concrete number.

@joshdistler
Copy link

Thanks Dave. Definitely looking forward to this very much as it's the only weakness in your otherwise amazing library.

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

No branches or pull requests

4 participants