From 75d570498e957be487284d1ce250865852fffa6f Mon Sep 17 00:00:00 2001 From: Equim Date: Wed, 21 Oct 2020 13:43:57 +0800 Subject: [PATCH] review: fix div-by-zero causing score to be NaN, close #14 --- src/review.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/review.rs b/src/review.rs index abdc9ff..4ec2ff2 100644 --- a/src/review.rs +++ b/src/review.rs @@ -304,7 +304,14 @@ pub fn review<'a>(review_args: &'a ReviewArgs) -> Result { } Some(Some(actual_ev)) => { - let move_score = 1f64 - (expected_ev - actual_ev) / (expected_ev - min_ev); + let range = expected_ev - min_ev; + let error = expected_ev - actual_ev; + let move_score = if range > 0f64 { + 1f64 - error / range + } else { + 1f64 + }; + let dev = expected_ev - actual_ev; if dev <= deviation_threshold { if verbose {