Skip to main content

primitive_float_rational_positive_difference_float

Function primitive_float_rational_positive_difference_float 

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

Computes the positive difference of a Rational and a primitive float — $x-y$ if $x>y$, and $+0.0$ otherwise — correctly rounding the result to the nearest value.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits().

§Examples

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

let d = primitive_float_rational_positive_difference_float(&Rational::from_signeds(22, 7), 3.0);
assert_eq!(NiceFloat(d), NiceFloat(0.14285714285714285));