MCPcopy Create free account
hub / github.com/buger/jsonparser / closeEnough

Function closeEnough

property_test.go:980–999  ·  view source on GitHub ↗

closeEnough reports whether two floats agree to within a relative tolerance suitable for decimal round-trip comparisons.

(a, b float64)

Source from the content-addressed store, hash-verified

978// closeEnough reports whether two floats agree to within a relative tolerance
979// suitable for decimal round-trip comparisons.
980func 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}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected