-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Proposal: decimal floating-point types #4221
Comments
There's also the general possibility of user-space defined Fixed Point storage. |
you should probably bring this up with llvm. This is a bunch of work (it needs a full soft float library) and that work would probably belong in llvm. |
That's true. Also clang does not have "(_Decimal32 and friends)" according to the manual https://clang.llvm.org/docs/UsersManual.html It is probably too much of a niche feature. |
Came across this article and adding this in could maybe help in places where COBOL is used: https://medium.com/the-technical-archaeologist/is-cobol-holding-you-hostage-with-math-5498c0eb428b |
This is identical to the more poorly named #1974. Though I disagree that a separate type should be reserved for it, since the type consists of a tuple (and it could be also done in libstd). There may be eventually some news on this, since another project lowers a functional language to zig and uses something in zig for that. |
At the moment, #1974 is only about binary fixed-point numbers, so it wouldn't help with this issue. |
They are very closely related: https://www.tutorialspoint.com/fixed-point-and-floating-point-number-representations, If you want to be fancy you could also use binary-coded decimals, thought thats less efficient (but might be useful for transformation etc). Its quite a pity that wikipedia does not properly explain it. |
@matu3ba, var x = 0.01; // type omitted
var i: i32 = 0;
while (i < 12) : (i += 1) {
x = 1.0 - 99 * x;
} At the end of the 12 iterations, To be clear, I'm highly skeptical of introducing native decimal fraction support in Zig. I'm just saying that if we do, then #1974 is not sufficient, unless it is extended to specify the base as well. |
It looks like decimal floating point is an optional feature in C23: https://www.iso.org/standard/68882.html GCC seems to have some amount of support for it: https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html Example usage: https://godbolt.org/z/d6EzqcrE6 There is talk of implementing this in Clang, but nothing tangible yet AFAICS: https://discourse.llvm.org/t/rfc-decimal-floating-point-support-iso-iec-ts-18661-2-and-c23/62152/1 |
What are your thoughts on Zig having decimal floating-point types built into the language? http://speleotrove.com/decimal/
They could have types df32 df64 df128 or something like that.
The text was updated successfully, but these errors were encountered: