pub trait MulAdd<A = Self, B = Self> {
    type Output;

    fn mul_add(self, a: A, b: B) -> Self::Output;
}
Expand description

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add.

Using mul_add can be more performant than an unfused multiply-add if the target architecture has a dedicated fma CPU instruction.

Note that A and B are Self by default, but this is not mandatory.

Example

use std::f32;

let m = 10.0_f32;
let x = 4.0_f32;
let b = 60.0_f32;

// 100.0
let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();

assert!(abs_difference <= 100.0 * f32::EPSILON);

Required Associated Types§

The resulting type after applying the fused multiply-add.

Required Methods§

Performs the fused multiply-add operation.

Implementations on Foreign Types§

Implementors§

impl<Frac, MulFrac: LeEqU8> MulAdd<FixedI8<MulFrac>, FixedI8<Frac>> for FixedI8<Frac>

impl<Frac, MulFrac: LeEqU16> MulAdd<FixedI16<MulFrac>, FixedI16<Frac>> for FixedI16<Frac>

impl<Frac, MulFrac: LeEqU32> MulAdd<FixedI32<MulFrac>, FixedI32<Frac>> for FixedI32<Frac>

impl<Frac, MulFrac: LeEqU64> MulAdd<FixedI64<MulFrac>, FixedI64<Frac>> for FixedI64<Frac>

impl<Frac, MulFrac: LeEqU128> MulAdd<FixedI128<MulFrac>, FixedI128<Frac>> for FixedI128<Frac>

impl<Frac, MulFrac: LeEqU8> MulAdd<FixedU8<MulFrac>, FixedU8<Frac>> for FixedU8<Frac>

impl<Frac, MulFrac: LeEqU16> MulAdd<FixedU16<MulFrac>, FixedU16<Frac>> for FixedU16<Frac>

impl<Frac, MulFrac: LeEqU32> MulAdd<FixedU32<MulFrac>, FixedU32<Frac>> for FixedU32<Frac>

impl<Frac, MulFrac: LeEqU64> MulAdd<FixedU64<MulFrac>, FixedU64<Frac>> for FixedU64<Frac>

impl<Frac, MulFrac: LeEqU128> MulAdd<FixedU128<MulFrac>, FixedU128<Frac>> for FixedU128<Frac>

impl<T: Clone + Num + MulAdd<Output = T>> MulAdd<Complex<T>, Complex<T>> for Complex<T>

impl<'a, 'b, T: Clone + Num + MulAdd<Output = T>> MulAdd<&'b Complex<T>, &'a Complex<T>> for &'a Complex<T>