-
Notifications
You must be signed in to change notification settings - Fork 0
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
Wrong result for a simple expression #3
Comments
Hey Tom, the library saves number literals as |
I just tried your example and modified it a little: MathExpression expression = new MathExpression("3.93+2.87+2.23+2.51+2.05+2+2.65+2.66+2.6+2.6+2.6+2.6+1.9+2.6+2.6");
double expected = 3.93 + 2.87 + 2.23 + 2.51 + 2.05 + 2 + 2.65 + 2.66 + 2.6 + 2.6 + 2.6 + 2.6 + 1.9 + 2.6 + 2.6;
Number result = expression.evaluate();
System.out.println("expression.value = " + result.getValue());
System.out.println("expected result: = " + expected); I got the following console output:
This shows again that the issue is rounding related to floating point rounding errors. If you wish to read more about why this happens, you can read this overview on StackExchange or this paper if you wish to get more in-depth information. Let me know if you need any other help with the library :) |
Hy,
I'm making this expression:
3.93 + 2.87 + 2.23 + 2.51 + 2.05 + 2+2.65 + 2.66 + 2.6 + 2.6 + 2.6 + 2.6 + 1.9 + 2.6 + 2.6
The result shoud be: 38.4
But I'm getting when running with the MathExpression as result: 38.400000000000006
Here the simple code:
MathExpression expression = new MathExpression("3.93+2.87+2.23+2.51+2.05+2+2.65+2.66+2.6+2.6+2.6+2.6+1.9+2.6+2.6"); System.out.println("expression.value = " + expression.evaluate().getValue());
Is this a bug in your library or what is here wrong?
Thanks,
Tom
The text was updated successfully, but these errors were encountered: