Decimal Floating-Point (DFP) types d32, d64 & d128?

Binary floating-point, through its non-alignment with decimal, will always inherently have some weird behaviour and/or compensations. So decimal floating-point seems to be a must-have for anything requiring precise numbers, e.g. financials. Wouldn't it be cool for this to become part of std in Rust?

Sadly most CPUs don't yet support it, with Intel and IBM having libraries instead and the Risc V extension not yet ratified. There are extremely low-versioned dfp crates. But there is stagnating work in clang, as well as compiler compile-time configuration in gcc that we might benfit from.

Wouldn't decimal fixed-point arithmetic be better suited to financial calculations?

4 Likes

While finance might have settled on base 10, you don't get exact numbers in decimal either. Good luck with 1/3.

Maybe what you want is rational numbers? But then what about the square root of 2? At some point you need to go fully symbolic like in CASes (computer algebra systems).

And to some problems a numeric approximation might be the best you can do anyway.

So calling decimal numbers precise is just plain wrong. And you might as well use base 12 since it has more divisors and is thus accurate more often. Base 60 like the Summerians and Babylonians used is perhaps even better.

3 Likes

There's too many choices right now, so it's better as a crate where things can compete and find the best APIs.

Should in-chip support for https://en.wikipedia.org/wiki/Decimal_floating_point#IEEE_754-2008_encoding start to become a thing, then sure, we'll probably add it to rust core, the same way we're talking about f16 & f128.

1 Like

Power ISA supports it.

And apparently SPARC64 does as well, but using the DPD encoding (as does Power)(Power uses BCD).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.