Skip to content
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

Issue: Floating point rounding errors #14

Open
incansvl opened this issue Apr 10, 2018 · 1 comment
Open

Issue: Floating point rounding errors #14

incansvl opened this issue Apr 10, 2018 · 1 comment

Comments

@incansvl
Copy link

ucum.js: 0.0.2

The library seems to suffer from the effects of number representation errors, I assume these are caused by using binary floating point arithmetic for internal calculations.

The effects may be minor (hopefully) when dealing with real-world measurements, but they do cause ugly results when converting "pure" units by powers of ten, e.g:

Input            Canonicalises To
pg/L             {"value":9.999999999999999e-10,"units":{"g":1,"m":-3}}
(implies 1 unit)

I believe this would would be improved using a high (or arbitrary) precision decimal arithmetic library within the module. Several such libraries are available on Github.

I realise this might be a significant rewrite, and would carry a speed penalty, but it would improve the usability of the library for unit conversion projects.

@jmandel
Copy link
Owner

jmandel commented Apr 10, 2018

Thanks for the comment! This library isn't actively maintained, but I'd be happy to accept a contribution to integrate a bigdecimal library like https://github.com/peterolson/BigRational.js/ (for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants