Skip to main content

primitive_float_sub_mul

Function primitive_float_sub_mul 

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

Subtracts the product of two primitive floats from another primitive float with a single rounding, using emulated Float arithmetic.

This is a correctly-rounded fused multiply-subtract: the product is not rounded before the subtraction, so the result is the true value of $x-yz$ rounded once to the nearest representable value. It agrees with the standard library’s hardware-backed mul_add with the multiplicand negated, up to argument order.

§Worst-case complexity

Constant time and additional memory.

§Examples

use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::sub_mul::*;

assert_eq!(
    NiceFloat(primitive_float_sub_mul(PI, E, SQRT_2)),
    NiceFloat(-0.7026383745693238)
);