Skip to content

Commit

Permalink
checkers/float: fix when is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
hieplpvip committed Dec 9, 2024
1 parent 3b4841d commit aee59c0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dmoj/checkers/floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit aee59c0

Please sign in to comment.