Skip to main content

weighted_average

Function weighted_average 

Source
pub fn weighted_average<T>(
    first_value: T,
    first_weight: T,
    second_value: T,
    second_weight: T,
) -> T
where T: Add<Output = T> + Mul<Output = T> + Div<Output = T> + Clone,
Expand description

Computes the weighted average of two values.

Returns (first_value * first_weight + second_value * second_weight) / (first_weight + second_weight).

ยงPanics

Panics on division by zero if both weights are zero.