-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
Given this code (playpen):
#![feature(i128_type,i128)]
fn cast(src: f32) -> Result<u128, &'static str> {
use std::{u128, f32};
Err(if src != src {
"NaN"
} else if src < u128::MIN as f32 {
"Underflow"
} else if src > u128::MAX as f32 {
"Overflow"
} else {
return Ok(src as u128);
})
}
fn main() {
let f = 2742605.0f32;
println!("{:?}", cast(f));
}It should print Ok(2742605). In release mode, that happens, but in debug mode, it prints Err("Overflow").
The value is mostly irrelevant, it would also work for 42.0.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team