std-method

Floating-point to_bits and from_bits

Inspect or restore the binary representation without converting the numerical magnitude to an integer. Expected stdout (not executed): 8000000000000000 true Common mistake: An as cast is numeric conversion, not bit reinterpretation.

Formal Syntax & Structure

rust syntaxrust
f64::to_bits(self) -> u64; f64::from_bits(u64) -> f64

Working Example

Example Snippetrust
fn main() {    let x = -0.0_f64;    println!("{:016x}", x.to_bits());    println!("{}", f64::from_bits(x.to_bits()).is_sign_negative());}
Rust Reference