PresearchOfficial / presearch-packages

Instant information packages for the Presearch engine
123 stars 49 forks source link

Calculator calcs wrong #168

Closed LightTemplar closed 1 year ago

LightTemplar commented 2 years ago

Describe the bug Enter 37.8+2.9 in the search field, calculator gives: = 40.699999999999996

Expected behavior The result should be: 40.7

Screenshots image

Desktop (please complete the following information):

Additional context Nothing more

manolinux commented 2 years ago

37.8+2.9

I think all math in the calculator should be implemented using a BigDecimal type, because Javascript's limited floating point math (IEEE-754) has this surprises, some numbers that can't be accurately represented. Same happened in Java, they included BigDecimal for arbitrary precission. An example library in JS that does the same: https://github.com/iriscouch/bigdecimal.js

manolinux commented 2 years ago

The package seems to do two things:

We han handle both things:

I include sample index.js for math package that seems to work (renamed to index.js.txt so that it's accepted here).

index.js.txt

Give me permissions (if you feel like) for creating a branch and doing a PR. Kind regards!

jejopl commented 2 years ago

Thanks @manolinux! Can you fork the repo, create a branch and then do a pull request? This is the way to contribute to presearch-packages repo

jejopl commented 1 year ago

Closing this one because it has been fixed by @manolinux. It will be pushed to production soon, thanks guys!