Skip to content

Conversation

@tgross35
Copy link
Contributor

Switch to parsing float literals for overflow checks using rustc_apfloat rather than host floats. This avoids small variations in platform support and makes it possible to start checking f16 and f128 as well.

Using APFloat matches what we try to do elsewhere to avoid platform inconsistencies.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tgross35 tgross35 added the F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` label Jan 23, 2026
$(impl GeneralFormat for $t {
fn already_rounded_value_should_use_exponential(&self) -> bool {
#[allow(overflowing_literals)] // f16 is always within this value
let max_abs = 1e+16;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this comment hard to understand. I think you're saying that 1e+16 is too big too represent as an f16, which is why we get the error, so we need to suppress that with the allow. Is the abs >= max_abs comparison still valid? Does 1e+16 get rounded up to positive infinity and therefore the comparison always fails?

Some more detail is needed to make this clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly it; abs >= 1e+16 is always true since f16 has a max of 65504.0. In context here, it just means that there isn't a f16 with a positive exponent that will get formatted in scientific notation by default.

I'll clarify this comment soon.

@nnethercote
Copy link
Contributor

Nice change. r=me with the nit fixed.

Switch to parsing float literals for overflow checks using
`rustc_apfloat` rather than host floats. This avoids small variations in
platform support and makes it possible to start checking `f16` and
`f128` as well.

Using APFloat matches what we try to do elsewhere to avoid platform
inconsistencies.
@tgross35
Copy link
Contributor Author

Thanks for reviewing, updated the comment to be more clear.

@bors r=nnethercote rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 27, 2026

📌 Commit 9b15010 has been approved by nnethercote

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 27, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 27, 2026
Rollup of 12 pull requests

Successful merges:

 - #147996 (Stabilize ppc inline assembly)
 - #148718 (Do not mention `-Zmacro-backtrace` for std macros that are a wrapper around a compiler intrinsic)
 - #151137 (checksum-freshness: Fix invalid checksum calculation for binary files)
 - #151680 (Update backtrace and windows-bindgen)
 - #150863 (Adds two new Tier 3 targets - `aarch64v8r-unknown-none{,-softfloat}`)
 - #151040 (Don't expose redundant information in `rustc_public`'s `LayoutShape`)
 - #151383 (remove `#[deprecated]` from unstable & internal `SipHasher13` and `24` types)
 - #151529 (lint: Use rustc_apfloat for `overflowing_literals`, add f16 and f128)
 - #151669 (rename uN::{gather,scatter}_bits to uN::{extract,deposit}_bits)
 - #151689 (Fix broken Xtensa installation link)
 - #151699 (Update books)
 - #151700 (os allow missing_docs)
// `max_abs` rounds to infinity for `f16`. This is fine to save us from a more
// complex macro, it just means a positive-exponent `f16` will never print as
// scientific notation by default (reasonably, the max is 65504.0).
#[allow(overflowing_literals)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rust-bors rust-bors bot merged commit af52352 into rust-lang:main Jan 27, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 27, 2026
rust-timer added a commit that referenced this pull request Jan 27, 2026
Rollup merge of #151529 - tgross35:lint-apfloat, r=nnethercote

lint: Use rustc_apfloat for `overflowing_literals`, add f16 and f128

Switch to parsing float literals for overflow checks using `rustc_apfloat` rather than host floats. This avoids small variations in platform support and makes it possible to start checking `f16` and `f128` as well.

Using APFloat matches what we try to do elsewhere to avoid platform inconsistencies.
@Zalathar
Copy link
Member

Perf results show regressions in tuple-stress, which seems potentially fine?

@Kobzol
Copy link
Member

Kobzol commented Jan 27, 2026

As long as this only shows up in stress tests, and provides more consistent behavior overall, I think it is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants