closeEnough reports whether two floats agree to within a relative tolerance suitable for decimal round-trip comparisons.
(a, b float64)
| 1099 | // closeEnough reports whether two floats agree to within a relative tolerance |
| 1100 | // suitable for decimal round-trip comparisons. |
| 1101 | func closeEnough(a, b float64) bool { |
| 1102 | if a == b { |
| 1103 | return true |
| 1104 | } |
| 1105 | const rel = 1e-15 |
| 1106 | diff := a - b |
| 1107 | if diff < 0 { |
| 1108 | diff = -diff |
| 1109 | } |
| 1110 | if a < 0 { |
| 1111 | a = -a |
| 1112 | } |
| 1113 | if b < 0 { |
| 1114 | b = -b |
| 1115 | } |
| 1116 | if a < b { |
| 1117 | a, b = b, a |
| 1118 | } |
| 1119 | return diff/a < rel |
| 1120 | } |
no outgoing calls
no test coverage detected