Skip to main content

primitive_float_positive_difference

Function primitive_float_positive_difference 

Source
pub fn primitive_float_positive_difference<T>(x: T, y: T) -> T
where Float: From<T> + PartialOrd<T>, for<'a> T: ExactFrom<&'a Float> + PrimitiveFloat,
Expand description

Computes the positive difference of two primitive floats — $x-y$ if $x>y$, and $+0.0$ otherwise — using emulated Float arithmetic.

This is C’s fdim, which the standard library does not provide. For finite operands the result equals x - y when x > y (the primitive subtraction is already correctly rounded) and a positive zero otherwise; a NaN input gives NaN.

§Worst-case complexity

Constant time and additional memory.

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::positive_difference::*;

assert_eq!(
    NiceFloat(primitive_float_positive_difference(3.0, 1.0)),
    NiceFloat(2.0)
);
assert_eq!(
    NiceFloat(primitive_float_positive_difference(1.0, 3.0)),
    NiceFloat(0.0)
);