closeEnough reports whether two floats agree to within a relative tolerance suitable for decimal round-trip comparisons.
(a, b float64)
| 978 | // closeEnough reports whether two floats agree to within a relative tolerance |
| 979 | // suitable for decimal round-trip comparisons. |
| 980 | func closeEnough(a, b float64) bool { |
| 981 | if a == b { |
| 982 | return true |
| 983 | } |
| 984 | const rel = 1e-15 |
| 985 | diff := a - b |
| 986 | if diff < 0 { |
| 987 | diff = -diff |
| 988 | } |
| 989 | if a < 0 { |
| 990 | a = -a |
| 991 | } |
| 992 | if b < 0 { |
| 993 | b = -b |
| 994 | } |
| 995 | if a < b { |
| 996 | a, b = b, a |
| 997 | } |
| 998 | return diff/a < rel |
| 999 | } |
no outgoing calls
no test coverage detected