Miri computes 2.0f64.powi(63) as 2^63 − 2048 instead of exactly 2^63, and thereby misses the float_to_int_unchecked UB
Author: Roticv912Created Sep 18, 2026Updated Sep 19, 2026
Miri evaluates 2.0f64.powi(63) to exactly 9223372036854773760 (= 2^63 − 2048, two ulps low), while rustc-compiled code on x86_64 produces the exact 9223372036854775808 (= 2^63); consequently float_to_int_unchecked::<f64, u64>(half + half) is not reported as UB under Miri, while the same call with the value written directly as a literal is reported correctly.
Program A
#![feature(core_intrinsics)]
use std::hint::black_box;
use std::intrinsics::float_to_int_unchecked;
fn main() {
let half: f64 = black_box(2.0f64.powi(63));
let full: f64 = black_box(half + half);
println!("half bits = {:#018x}, exact = {}", half.to_bits(), half as u128);
let out = unsafe { float_to_int_unchecked::<f64, u64>(full) };
println!("out = {out}");
}Program B
#![feature(core_intrinsics)]
use std::hint::black_box;
use std::intrinsics::float_to_int_unchecked;
fn main() {
let half: f64 = black_box(9223372036854775808.0); // exactly 2^63
let full: f64 = black_box(half + half);
let _out = unsafe { float_to_int_unchecked::<f64, u64>(full) };
}Results of Program A
# A under miri —— no UB reported:
half bits = 0x43dffffffffffffe, exact = 9223372036854773760
out = 18446744073709547520
EXIT=0
# A under rustc (native) —— exact value:
half bits = 0x43e0000000000000, exact = 9223372036854775808
out = 9223372036854775808
EXIT=0Results of Program B
# B under miri —— UB reported:
error: Undefined Behavior: `float_to_int_unchecked` intrinsic called on 1.8446744073709552E+19f64 which cannot be represented in target type `u64`
EXIT=1Source: rust-lang/miri