fubark / cyber

Fast and concurrent scripting.
https://cyberscript.dev
MIT License
1.21k stars 43 forks source link

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

Open dumblob opened 1 year ago

dumblob commented 1 year ago

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 https://github.com/vlang/v/issues/5180#issuecomment-675732199

Or in the worst case at least implement https://github.com/vlang/v/issues/9915 .

matu3ba commented 1 year ago

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.