math-expressions icon indicating copy to clipboard operation
math-expressions copied to clipboard

[Bug] Wrong result for numbers more than 16 digits

Open Sp4Rx opened this issue 4 years ago • 1 comments

Wrong result comes for numbers more than 16 digits. For example

Expression expression = Parser().parse('88888888888888888');
print(expression.toString());

Expected result should be 88888888888888888 but we get 88888888888888900.0 which is wrong.

NB: This happens for each and every number.

If possible, please provide a resolution ASAP as I'm using it in my production app.

Sp4Rx avatar Jul 23 '20 21:07 Sp4Rx

Hi @Sp4Rx, thanks for the report.

You are running into a limitation of the datatype that is used to represent numbers within this library. Numbers are handled as regular double values which are 64 bit double-precision floating point numbers. They only offer roughly up to 15 digits of precision.

This could be improved by utilising a big decimal representation, for example as implemented by decimal.

I don't have plans to implement this anytime soon, but contributions are welcome.

fkleon avatar Jul 24 '20 20:07 fkleon