Function abs_sub

1.0.0 · Source
pub fn abs_sub(x: f32, other: f32) -> f32
👎Deprecated since 1.10.0: you probably meant (self - other).abs(): this operation is (self - other).max(0.0) except that abs_sub also propagates NaNs (also known as fdimf in C). If you truly need the positive difference, consider using that expression or the C function fdimf, depending on how you wish to handle NaN (please consider filing an issue describing your use-case too).
Expand description

Experimental version of abs_sub in core. See f32::abs_sub for details.

§Examples

#![feature(core_float_math)]

use core::f32;

let x = 3.0f32;
let y = -3.0f32;

let abs_difference_x = (f32::abs_sub(x, 1.0) - 2.0).abs();
let abs_difference_y = (f32::abs_sub(y, 1.0) - 0.0).abs();

assert!(abs_difference_x <= f32::EPSILON);
assert!(abs_difference_y <= f32::EPSILON);

This standalone function is for testing only. It will be stabilized as an inherent method.