-
Notifications
You must be signed in to change notification settings - Fork 13.3k
f64 formatting panic with 'arithmetic operation overflowed' #23150
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
Labels
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Comments
It also happens with 9.5 but not with 9.499. The formatting routine tries to round, but fails to handle the case that rounding extends the digits. |
Just to clarify: this is not actually an ICE because the program is panicking, not the compiler. So, compilation is fine, but the program fails at runtime |
benashford
added a commit
to benashford/rust
that referenced
this issue
Apr 10, 2015
Merged
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Apr 11, 2015
…ichton This fixes the bug described in issue rust-lang#23150. This affected formatting any floating point number into a string in a formatting pattern that: a) required rounding up, and b) required an extra digit on the front. So `format!(\"{:.0}\", 9.9)` would fail, but `format!(\"{:.0}\", 8.9)` would succeed. This was due to a negative integer being cast to a `usize` resulting in an 'arithmetic operation overflowed' panic. The fix was to change the order of operations so that the number is zero before casting.
bors
added a commit
that referenced
this issue
Apr 11, 2015
This fixes the bug described in issue #23150. This affected formatting any floating point number into a string in a formatting pattern that: a) required rounding up, and b) required an extra digit on the front. So `format!("{:.0}", 9.9)` would fail, but `format!("{:.0}", 8.9)` would succeed. This was due to a negative integer being cast to a `usize` resulting in an 'arithmetic operation overflowed' panic. The fix was to change the order of operations so that the number is zero before casting.
3 tasks
This issue should be closed as it's now fixed. |
Yay! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a minimal example which results in a runtime error:
I'd expect that format string to work (precision=0, so no digits after the decimal point), but here's what I get with RUST_BACKTRACE=1:
Ubuntu 14.10 / 64-bit
rustc 1.0.0-nightly (b0746ff 2015-03-05) (built 2015-03-06)
binary: rustc
commit-hash: b0746ff
commit-date: 2015-03-05
build-date: 2015-03-06
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
The text was updated successfully, but these errors were encountered: