# Function mul_add

Source

    pub fn mul_add(x: f32, y: f32, z: f32) -> f32

🔬This is a nightly-only experimental API. (`core_float_math` #137578)
Expand description

Experimental version of `mul_add` in `core`. See `f32::mul_add` for details.

## §Examples

    #![feature(core_float_math)]

    use core::f32;

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

    assert_eq!(f32::math::mul_add(m, x, b), 100.0);
    assert_eq!(m * x + b, 100.0);

    let one_plus_eps = 1.0_f32 + f32::EPSILON;
    let one_minus_eps = 1.0_f32 - f32::EPSILON;
    let minus_one = -1.0_f32;

    // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps.
    assert_eq!(
        f32::math::mul_add(one_plus_eps, one_minus_eps, minus_one),
        -f32::EPSILON * f32::EPSILON
    );
    // Different rounding with the non-fused multiply and add.
    assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0);

This standalone function is for testing only. It will be stabilized as an inherent method.