- Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-bugCategory: This is a bug.Category: This is a bug.
Description
I tried this code:
fn main() { let mut n: i64 = 0b0000000000111111111111111111111111011111111111111111111111111111; println!("{}, {}, {}, {}", n, n as i64 as f32, n as u64 as f32, n as u128 as f32); assert_ne!((n as f64) as f32, n as f32); assert_eq!(n as i64 as f32, n as u64 as f32); n = -n; assert_ne!((n as f64) as f32, n as f32); assert_eq!(n as i64 as f32, -(-n as u64 as f32)); }I expected to see this happen:
The code prints the output below and exits successfully.
18014397972611071, 18014397000000000, 18014397000000000, 18014397000000000 Instead, this happened:
The code prints the output below and panics.
18014397972611071, 18014397000000000, 18014399000000000, 18014397000000000 Meta
rustc --version --verbose:
rustc 1.65.0 (897e37553 2022-11-02) binary: rustc commit-hash: 897e37553bba8b42751c67658967889d11ecd120 commit-date: 2022-11-02 host: x86_64-pc-windows-msvc release: 1.65.0 LLVM version: 15.0.0 Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-bugCategory: This is a bug.Category: This is a bug.