std-method
Floating-point abs, signum and copysign
Use magnitude separately from sign. copysign combines the magnitude of one operand with the sign of another. Expected stdout (not executed): 6.5 -1 -4 Common mistake: signum on signed zero returns a signed unit, not zero.
Formal Syntax & Structure
rust syntaxrust
x.abs(); x.signum(); x.copysign(y)Working Example
Example Snippetrust
fn main() { let x = -6.5_f64; println!("{} {} {}", x.abs(), x.signum(), 4.0_f64.copysign(x));}