[][src]Function ieee754::abs

pub fn abs<F: Ieee754>(x: F) -> F

Return the absolute value of x.

This provides a no_std/core-only version of the built-in abs in std, until #50145 is addressed.

use std::{f32, f64};

assert_eq!(ieee754::abs(0_f32), 0.0);
assert_eq!(ieee754::abs(0_f64), 0.0);

assert_eq!(ieee754::abs(12.34_f32), 12.34);
assert_eq!(ieee754::abs(-12.34_f64), 12.34);

assert!(ieee754::abs(f32::NAN).is_nan());
assert_eq!(ieee754::abs(f64::NEG_INFINITY), f64::INFINITY);