-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
lint: Use rustc_apfloat for overflowing_literals, add f16 and f128
#151529
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,14 @@ macro_rules! impl_general_format { | |
| ($($t:ident)*) => { | ||
| $(impl GeneralFormat for $t { | ||
| fn already_rounded_value_should_use_exponential(&self) -> bool { | ||
| // `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)] | ||
| let max_abs = 1e+16; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Some more detail is needed to make this clear.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's exactly it; I'll clarify this comment soon. |
||
|
|
||
| let abs = $t::abs(*self); | ||
| (abs != 0.0 && abs < 1e-4) || abs >= 1e+16 | ||
| (abs != 0.0 && abs < 1e-4) || abs >= max_abs | ||
| } | ||
| })* | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| //@ compile-flags: -O | ||
|
|
||
| #![feature(f16)] | ||
| #![feature(f128)] | ||
| #![deny(overflowing_literals)] | ||
|
|
||
| fn main() { | ||
| let x2: i8 = --128; //~ ERROR literal out of range for `i8` | ||
| //~| WARN use of a double negation | ||
|
|
||
| let x = -65520.0_f16; //~ ERROR literal out of range for `f16` | ||
| let x = 65520.0_f16; //~ ERROR literal out of range for `f16` | ||
| let x = -3.40282357e+38_f32; //~ ERROR literal out of range for `f32` | ||
| let x = 3.40282357e+38_f32; //~ ERROR literal out of range for `f32` | ||
| let x = -1.7976931348623159e+308_f64; //~ ERROR literal out of range for `f64` | ||
| let x = 1.7976931348623159e+308_f64; //~ ERROR literal out of range for `f64` | ||
| let x = -1.1897314953572317650857593266280075e+4932_f128; //~ ERROR literal out of range for `f128` | ||
| let x = 1.1897314953572317650857593266280075e+4932_f128; //~ ERROR literal out of range for `f128` | ||
| } |
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.
👍