Trait num::traits::MulAdd

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

    // Required method
    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§

source

type Output

The resulting type after applying the fused multiply-add.

Required Methods§

source

fn mul_add(self, a: A, b: B) -> Self::Output

Performs the fused multiply-add operation (self * a) + b

Implementations on Foreign Types§

source§

impl MulAdd for f32

source§

type Output = f32

source§

fn mul_add(self, a: f32, b: f32) -> <f32 as MulAdd>::Output

source§

impl MulAdd for f64

source§

type Output = f64

source§

fn mul_add(self, a: f64, b: f64) -> <f64 as MulAdd>::Output

source§

impl MulAdd for i8

source§

type Output = i8

source§

fn mul_add(self, a: i8, b: i8) -> <i8 as MulAdd>::Output

source§

impl MulAdd for i16

source§

type Output = i16

source§

fn mul_add(self, a: i16, b: i16) -> <i16 as MulAdd>::Output

source§

impl MulAdd for i32

source§

type Output = i32

source§

fn mul_add(self, a: i32, b: i32) -> <i32 as MulAdd>::Output

source§

impl MulAdd for i64

source§

type Output = i64

source§

fn mul_add(self, a: i64, b: i64) -> <i64 as MulAdd>::Output

source§

impl MulAdd for i128

source§

type Output = i128

source§

fn mul_add(self, a: i128, b: i128) -> <i128 as MulAdd>::Output

source§

impl MulAdd for isize

source§

impl MulAdd for u8

source§

type Output = u8

source§

fn mul_add(self, a: u8, b: u8) -> <u8 as MulAdd>::Output

source§

impl MulAdd for u16

source§

type Output = u16

source§

fn mul_add(self, a: u16, b: u16) -> <u16 as MulAdd>::Output

source§

impl MulAdd for u32

source§

type Output = u32

source§

fn mul_add(self, a: u32, b: u32) -> <u32 as MulAdd>::Output

source§

impl MulAdd for u64

source§

type Output = u64

source§

fn mul_add(self, a: u64, b: u64) -> <u64 as MulAdd>::Output

source§

impl MulAdd for u128

source§

type Output = u128

source§

fn mul_add(self, a: u128, b: u128) -> <u128 as MulAdd>::Output

source§

impl MulAdd for usize

Implementors§

source§

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

source§

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