Function scale_add

Source
pub fn scale_add<T, U>(s: T, a: U, b: U) -> U
where T: Float, U: QuaternionOps<T>,
Expand description

Scaling and addition in one step: s * a + b

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 v_result = scale_add(2.0, v1, v2);
 
assert!( (2.1 - v_result[0]).abs() < 1e-12 );
assert!( (4.2 - v_result[1]).abs() < 1e-12 );
assert!( (6.3 - 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 q_result = scale_add(2.0, q1, q2);
 
assert!( (2.1 - q_result.0).abs() < 1e-12 );
assert!( (4.2 - q_result.1[0]).abs() < 1e-12 );
assert!( (6.3 - q_result.1[1]).abs() < 1e-12 );
assert!( (8.4 - q_result.1[2]).abs() < 1e-12 );