From b80f16610a1f27d82f8a21e8b2cbeed5526ec573 Mon Sep 17 00:00:00 2001
From: Le Bao Hiep <baohiep2013@gmail.com>
Date: Mon, 9 Dec 2024 23:11:09 +0700
Subject: [PATCH] checkers/float: fix `error_relative` when `judge_float` is 0

---
 dmoj/checkers/floats.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/dmoj/checkers/floats.py b/dmoj/checkers/floats.py
index 5eceacb29..453c56b72 100644
--- a/dmoj/checkers/floats.py
+++ b/dmoj/checkers/floats.py
@@ -28,7 +28,10 @@ def verify_relative(process_float: float, judge_float: float, epsilon: float) ->
 
 def error_relative(process_float: float, judge_float: float) -> float:
     absolute = abs(process_float - judge_float)
-    return abs(absolute / judge_float)
+    # if judge_float is too small, we return absolute error instead
+    if abs(judge_float) > 1e-9:
+        return abs(absolute / judge_float)
+    return absolute
 
 
 def verify_default(process_float: float, judge_float: float, epsilon: float) -> bool:
@@ -43,7 +46,7 @@ def verify_default(process_float: float, judge_float: float, epsilon: float) ->
 
 def error_default(process_float: float, judge_float: float) -> float:
     absolute = abs(process_float - judge_float)
-    # if jude_float is too small, we return absolute error instead
+    # if judge_float is too small, we return absolute error instead
     if abs(judge_float) > 1e-9:
         return min(absolute, abs(absolute / judge_float))
     return absolute