Skip to main content

primitive_float_min_rational

Function primitive_float_min_rational 

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

Computes the smaller of a primitive float and a Rational, correctly rounding the result to the nearest value.

The comparison is exact, and only the winning operand is rounded, so the right operand is selected even when converting the Rational to a primitive float first would land on the other side of the comparison. A NaN input yields the Rational, 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 y.significant_bits().

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::comparison::min_max::primitive_float_min_rational;
use malachite_q::Rational;

assert_eq!(
    NiceFloat(primitive_float_min_rational(
        3.0,
        &Rational::from_signeds(22, 7)
    )),
    NiceFloat(3.0)
);