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

Add Option to Use decimal.js #2467

Open
equt opened this issue Nov 1, 2024 · 0 comments
Open

Add Option to Use decimal.js #2467

equt opened this issue Nov 1, 2024 · 0 comments
Labels
feature-request New feature or request.

Comments

@equt
Copy link

equt commented Nov 1, 2024

Is your feature request related to a problem? Please describe.

It's always a surprise for those know little about IEEE 754 when they first saw 0.1 + 0.2 != 0.3, like

Describe the solution you'd like

Add an option (default to false), and use decimal.js as the underneath implementation in

BinaryOpHandler.create()
// TODO: Consider not using a universal comparison function.
.compare("*", (a, b) => Values.compareValue(a, b, linkNormalizer))
// Global boolean operations.
.register("*", "&", "*", (a, b) => Values.isTruthy(a) && Values.isTruthy(b))
.register("*", "|", "*", (a, b) => Values.isTruthy(a) || Values.isTruthy(b))
// Number implementations.
.register("number", "+", "number", (a, b) => a + b)
.register("number", "-", "number", (a, b) => a - b)
.register("number", "*", "number", (a, b) => a * b)
.register("number", "/", "number", (a, b) => a / b)
.register("number", "%", "number", (a, b) => a % b)

Describe alternatives you've considered

IDK, maybe add some reminders in the numeric operations doc?

Additional context

Of course, an arbitrary-precision implementation would hurt performance, but I believe it's OK for such scenario.


edited: as I hit the cmd enter too early :(
ps: happy to PR if it's worth doing for the core team

@equt equt added the feature-request New feature or request. label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant