Skip to main content

primitive_float_rational_rem_float

Function primitive_float_rational_rem_float 

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

Computes the remainder of a Rational by a primitive float, with the quotient rounded toward zero, correctly rounding the result to the nearest value.

The Rational dividend is used exactly. NaN or zero y gives NaN; an infinite y returns the dividend, 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::rem::primitive_float_rational_rem_float;
use malachite_q::Rational;

// 22/7 mod 3 = 1/7
assert_eq!(
    NiceFloat(primitive_float_rational_rem_float(
        &Rational::from_signeds(22, 7),
        3.0
    )),
    NiceFloat(0.14285714285714285)
);