Code Monkey home page Code Monkey logo

Comments (3)

vatbub avatar vatbub commented on June 20, 2024

Hey Tom, the library saves number literals as doubles, the calculations are hence carried out using double precision. To me, this looks like usual rounding errors which occur when doing floating point calculations. I will have a closer look at it later today.

from mathevaluator.

vatbub avatar vatbub commented on June 20, 2024

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:

expression.value = 38.400000000000006
expected result: = 38.400000000000006

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 :)

from mathevaluator.

vatbub avatar vatbub commented on June 20, 2024

Apart from that, you may want to pull and run mvn install again as I just fixed issues #1 and #2 .
Cheers :)

from mathevaluator.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.