Add `f16` formatting and parsing by tgross35 · Pull Request #127013 · rust-lang/rust

@rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Jun 27, 2024

fbstj

@Dylan-DPC Dylan-DPC added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Aug 20, 2024

@rustbot rustbot added the T-bootstrap

Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

label

Aug 25, 2024

@tgross35

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), matching other
floats, and adds a `FromStr` implementation.

In order to avoid crashes when compiling with Cranelift or on targets
where f16 is not well supported, a fallback is used if
`cfg(target_has_reliable_f16)` is not true.

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 18, 2025
Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: x86_64-gnu-aux
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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 18, 2025
Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: x86_64-gnu-aux

fmease added a commit to fmease/rust that referenced this pull request

May 18, 2025
…Simulacrum

Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: x86_64-gnu-aux

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 18, 2025

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request

May 21, 2025
…mulacrum

Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: x86_64-gnu-aux

rust-bors bot pushed a commit that referenced this pull request

Jun 9, 2025
Upstream Rust currently does not support printing f16s in decimal.
For the intrinsics tests to work, make C++ print float16_t in the same
format.

Can be droppen once #127013
is merged.

tautschnig pushed a commit to model-checking/verify-rust-std that referenced this pull request

Jul 3, 2025
Upstream Rust currently does not support printing f16s in decimal.
For the intrinsics tests to work, make C++ print float16_t in the same
format.

Can be droppen once rust-lang#127013
is merged.