-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 f16
formatting and parsing
#127013
base: master
Are you sure you want to change the base?
Add f16
formatting and parsing
#127013
Conversation
This comment has been minimized.
This comment has been minimized.
@rustbot label +rla-silenced |
@rustbot label +F-f16_and_f128 |
This will need #127510 |
☔ The latest upstream changes (presumably #127020) made this pull request unmergeable. Please resolve the merge conflicts. |
7c3f9c1
to
f3ebeb3
Compare
Update: I'm really just waiting on #128083 to bump stage0, managing |
☔ The latest upstream changes (presumably #128360) made this pull request unmergeable. Please resolve the merge conflicts. |
2eaa479
to
422c52e
Compare
21ffabc
to
2098f01
Compare
404089f
to
3636530
Compare
@@ -1,3 +1,5 @@ | |||
#![feature(f16)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this will require changing
rust/src/bootstrap/src/core/build_steps/tool.rs
Line 1243 in 8c39296
allow_features: "", |
to allow f16
btw.
a6d693d
to
2bc1e4e
Compare
@speedy-lex I got this rebased on top of #134063 which should hopefully merge reasonably soon. Any chance you are interested in taking this over? I'm happy to keep going of course, but it seems like you may have already done some of the work :) |
I think I will rewrite some of the tests in ./library/coretests/tests/num/flt2dec/mod.rs for f16. Also if you want to use this, I made a calculator for f16 (which is useful for the exact_sanity_test): https://www.desmos.com/calculator/ikaghp8on9 |
That would be great; I'm also happy to add any patches here that you work on.
Awesome, more float tools! My usuals are https://float.exposed/0x0001 and https://weitz.de/ieee/ :) (Am I supposed to see something on the desmos plot?) |
2bc1e4e
to
c1f042b
Compare
No, the desmos plot should be empty, the float is just the result of that summation. |
@tgross35, how do you want me to contribute my changes? Should I make a PR on your repo? Edit: I'm working on the flt2dec tests |
Post links to the relevant commits / branch here and I’ll pick them up 👍 or feel free to pick up my commits and open a new PR here |
@tgross35, I've ported the tests for flt2dec over to f16. This is the commit: speedy-lex@09643f9 Edit: Could you try add |
PR for fixing off by one error in test-float-parse #137948 |
@@ -83,7 +82,13 @@ where | |||
} | |||
|
|||
fn new() -> Self { | |||
Self { iter: F::Int::ZERO..=min(F::Int::ONE << 22, F::MAN_BITS.try_into().unwrap()) } | |||
let upper_lim = if F::MAN_BITS < 22 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this check is correct?
I have a feeling it might need to be F::MAN_BITS >= 22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might also be why https://github.com/rust-lang/rust/actions/runs/13614968407/job/38056857277?pr=127013 is failing (F::MAN_BITS
is 10 so F::Int::ONE << 22
runs, but 1u16 << 22 will overflow. This aligns with the error of overflow on shl)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this check is correct?
Nope :) I think I ran this all once or twice then got distracted and never came back. Thanks for pointing it out, I'll double check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks wrong but works for some reason (except for in the CI job)
I don't think I've ever used this and I have no idea how it works 😆 any improvements to running test-float-parse via bootstrap are welcome though, I wired it up just enough to run tests in CI. |
I'm not very familiar with the CI system; can you link me to where you wired it up? |
|
Doesn't CI use it? |
It does not AFAIK. It was mostly added to help local developers. #109933 I don't think it's been worked on for a while. |
What's the system for registering CI commands? |
The CI goes through some shell wrappers What do you want to do with "registering CI commands"? CI also goes through bootstrap. Footnotes
|
c1f042b
to
18e5709
Compare
Thanks @speedy-lex for the tests, almost everything is passing (including test-float-parse!). I have a few
Bootstrap can be set up to build a path as a crate, rust/src/bootstrap/mk/Makefile.in Lines 51 to 55 in 91a0e16
|
@tgross35, I've figured out CI on my own already but thanks for commenting. Also, what else needs to be done before this is finished? |
There are a few small places where I added tests for consistency but didn’t yet update them, labeled After that this should be review-ready |
check_exact!(f(f16::MIN_POSITIVE) => b"6103515625 ", -4); | ||
check_exact!(f(minf16) => b"59604644775390625", -7); | ||
|
||
// todo: add tables from f32 and f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the last thing remaining to do, I think it might take a bit of work to apply the algorithms from the Paxson paper to binary16. @speedy-lex have you touched this at all?
(I'm working on it, thinking the described algorithm would be good in test-float-parse)
Use the existing Lemire (decimal -> float) and Dragon / Grisu algorithms (float -> decimal) to add support for `f16`. This allows updating the implementation for `Display` to the expected behavior for `Display` (currently it prints the a hex bitwise representation) and adds a `FromStr` implementation.
Extend the existing tests for `f32` and `f64` with versions that include `f16`'s new printing and parsing implementations. Co-authored-by: Speedy_Lex <alex.ciocildau@gmail.com>
This requires a fix to the subnormal test to cap the maximum allowed value within the maximum mantissa.
6ba3e9d
to
3bb0af3
Compare
WIP
r? @ghost