Skip to content

Commit

Permalink
Attempt to catch error where NaN is introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieMcKinstry committed Nov 29, 2024
1 parent 4cbbdc1 commit c7c532b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stats/chi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ fn test_statistic<const N: usize, C: Categorical<N>>(table: &ContingencyTable<N,
let observed_count = table.observed_by_index(i) as i64;
let diff = observed_count - expected_count;
let error = diff.pow(2) as f64;
let incremental_error = error / (expected_count as f64);
let incremental_error = error / (expected_count as f64).min(1.0);
debug_assert!(!incremental_error.is_nan(), "The error must never be NaN.");
sum += incremental_error;
}
sum
Expand Down

0 comments on commit c7c532b

Please sign in to comment.