fix Batch modes

This commit is contained in:
Rachel Powers
2024-04-14 23:56:12 -07:00
parent f29f4d7adc
commit dc0ae7d4c7

View File

@@ -1399,15 +1399,18 @@ impl BatchMode {
pub fn apply(&self, samples: &[f64]) -> f64 {
match self {
BatchMode::Sum => samples.iter().sum(),
/// Both c-charp and rust return NaN for 0.0/0.0 so we're good here
BatchMode::Average => samples.iter().copied().sum::<f64>() / samples.len() as f64,
/// Game uses a default of Positive INFINITY for Minimum
BatchMode::Minimum => *samples
.iter()
.min_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap_or(&0.0),
.unwrap_or(&f64::INFINITY),
/// Game uses default of NEG_INFINITY for Maximum
BatchMode::Maximum => *samples
.iter()
.max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap_or(&0.0),
.unwrap_or(&f64::NEG_INFINITY),
}
}
}