pub fn hadamard_add<T, U>(a: U, b: U, c: U) -> Uwhere
T: Float,
U: QuaternionOps<T>,Expand description
Hadamard product and addition in one step.
If the fma feature is enabled, the FMA calculation is performed using
the mul_add method (s.mul_add(a, b)).
If not enabled, it’s computed by unfused multiply-add (s * a + b).
§Examples
// --- Vector3 --- //
let v1: Vector3<f64> = [1.0, 2.0, 3.0];
let v2: Vector3<f64> = [0.1, 0.2, 0.3];
let v3: Vector3<f64> = [0.4, 0.5, 0.6];
let v_result = hadamard_add(v1, v2, v3);
assert!( (0.5 - v_result[0]).abs() < 1e-12 );
assert!( (0.9 - v_result[1]).abs() < 1e-12 );
assert!( (1.5 - v_result[2]).abs() < 1e-12 );
// --- Quaternion --- //
let q1: Quaternion<f64> = (1.0, [2.0, 3.0, 4.0]);
let q2: Quaternion<f64> = (0.1, [0.2, 0.3, 0.4]);
let q3: Quaternion<f64> = (0.5, [0.6, 0.7, 0.8]);
let q_result = hadamard_add(q1, q2, q3);
assert!( (0.6 - q_result.0).abs() < 1e-12 );
assert!( (1.0 - q_result.1[0]).abs() < 1e-12 );
assert!( (1.6 - q_result.1[1]).abs() < 1e-12 );
assert!( (2.4 - q_result.1[2]).abs() < 1e-12 );