DDMathParser
DDMathParser copied to clipboard
Doubles are imprecise
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
Well I just saw you added usesHighPrecisionEvaluation. It seems to fix the issue with stringValue but doesn't fix it with doubleValue
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.
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.
I would love to see an infinite-precision implementation here. In testing, I'm seeing: 45.25 - 45 = 0.230000000000004. Any easy fix?
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.
Thanks Dave. Definitely looking forward to this very much as it's the only weakness in your otherwise amazing library.