Skip to content

Commit

Permalink
floatのepsを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshihiro Shimizu authored and Toshihiro Shimizu committed Nov 6, 2023
1 parent fb1352c commit 3b22bbf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/atcoder/extra/other/floatutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ when not declared ATCODER_FLOAT_UTILS_HPP:
Real$.pi = pi()
#echo machineEpsilon(Real)
#Real$.eps = machineEpsilon(Real) * Real(10000)
block:
let one = Real(1)
var eps2 = one
while not (one + eps2 == one):
eps2 = eps2 / Real(2)
Real$.eps = eps2 * Real(5000)
when Real is float:
Real$.eps = 1e-12
when Real is float | float64:
Real$.eps = 1e-9
elif Real is float32:
Real$.eps = 1e-7
else:
block:
let one = Real(1)
var eps2 = one
while not (one + eps2 == one):
eps2 = eps2 / Real(2)
Real$.eps = eps2 * Real(1000000)

# float comp
# TODO: relative error
proc `=~`*(a, b: Real): bool = abs(a - b) < Real$.eps
proc `!=~`*(a, b: Real): bool = abs(a - b) > Real$.eps
Expand Down

0 comments on commit 3b22bbf

Please sign in to comment.