expression
Floating-point signed zero
Positive and negative zero compare equal but retain different signs. Reciprocal division can reveal the difference. Expected stdout (not executed): true true true Common mistake: Equality does not distinguish the sign bits of zero.
Formal Syntax & Structure
rust syntaxrust
0.0_f64; -0.0_f64; x.is_sign_negative()Working Example
Example Snippetrust
fn main() { let z = -0.0_f64; println!("{} {}", z == 0.0, z.is_sign_negative()); println!("{}", (1.0/z) == f64::NEG_INFINITY);}