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

(almost) unbounded decimals by default (instead of floating point) #28

Open
dumblob opened this issue Jan 28, 2023 · 1 comment
Open

Comments

@dumblob
Copy link

dumblob commented Jan 28, 2023

How about becoming the first modern language with safe numbers?

mpdecimal could be used as the backend (of course, if static analysis proves smaller boundaries, this should be refined to a much more close-to-bare-metal number type).

Explanation with numerous examples in vlang/v#5180 (comment)

Or in the worst case at least implement vlang/v#9915 .

@matu3ba
Copy link

matu3ba commented Jan 31, 2023

Zig (and probably me) plans to implement the compiler_rt decimal routines (https://github.com/ziglang/zig/tree/d6b430b520103fb6691b2c18ae06c2f2a360e806/lib/compiler_rt#readme).
Keep in mind however, that decimals have no hardware acceleration for common hardware (instructions are in x86, but not x86_64).
The main caveat of using those is that they make things unpredictably slow due to the necessary first check + allocation of (for BID how to represent the number sufficiently accurately).
This could also be the reason, why libgcc has The software decimal floating point library supports either DPD (Densely Packed Decimal) or BID (Binary Integer Decimal) encoding as selected at configure time. to make perf at least somewhat more deterministic (you either need general absolute accuracy or only accuracy wrt 2s complement rational numbers).

Sidenode: Zig already has arbitrary precision integers, which have simpler checks and are planned to be exported.
I would assume that the rationals implementation will also be exported, as it complements arbitrary length integers.

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