Skip to main content

primitive_float_max_rational

Function primitive_float_max_rational 

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

Computes the larger 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. 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_max_rational;
use malachite_q::Rational;

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