pub trait MulAddRef {
// Required method
fn mul_add_ref(self, b: &Self, c: &Self) -> Self;
}
Expand description
Trait for fused multiply-add operations.
This trait provides methods for computing (self * b) + c
efficiently.
§Why a custom MulAddRef
trait?
This trait is distinct from num_traits::MulAdd
primarily in its method signatures,
which take b
and c
by reference (&Self
). This is a deliberate design choice to:
- Maintain API Consistency: Aligns with the other operator traits in this library that support by-reference operations.
- Reduce Cloning: Allows implementors to avoid cloning values in performance-sensitive
contexts, which is especially important for non-
Copy
types likerug::Float
.
Implementors should aim to use hardware FMA (Fused Multiply-Add) instructions where available and appropriate for the underlying scalar type to improve performance and accuracy.
Required Methods§
Sourcefn mul_add_ref(self, b: &Self, c: &Self) -> Self
fn mul_add_ref(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add_ref(b, c)
produces a result like a * &b + &c
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl MulAddRef for f64
Implementation of the MulAddRef
trait for f64
.
impl MulAddRef for f64
Implementation of the MulAddRef
trait for f64
.
Source§fn mul_add_ref(self, b: &Self, c: &Self) -> Self
fn mul_add_ref(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c)
produces a result like a * &b + &c
.
Source§impl MulAddRef for Complex<f64>
Implementation of the MulAddRef
trait for Complex<f64>
.
impl MulAddRef for Complex<f64>
Implementation of the MulAddRef
trait for Complex<f64>
.
Source§fn mul_add_ref(self, b: &Self, c: &Self) -> Self
fn mul_add_ref(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c)
produces a result like a * &b + &c
.