Skip to main content

primitive_float_add_mul_rational

Function primitive_float_add_mul_rational 

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

Adds a primitive float and the product of another primitive float and a Rational, with a single rounding, using emulated Float arithmetic.

The Rational multiplicand enters the product exactly, and the result is the true value of $x+yz$ rounded once to the nearest representable value.

§Worst-case complexity

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

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

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

§Examples

use core::f64::consts::{E, PI};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::add_mul::*;
use malachite_q::Rational;

assert_eq!(
    NiceFloat(primitive_float_add_mul_rational(
        PI,
        E,
        &Rational::from_signeds(1, 3)
    )),
    NiceFloat(4.047686596409475)
);