ECMA safe values
diff --git a/utils.go b/utils.go
index e4b417a..cfeb628 100644
--- a/utils.go
+++ b/utils.go
@@ -90,9 +90,15 @@
}
+// same as ECMA Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
+const (
+ max_json_float = float64(1<<53 - 1) // 9007199254740991.0 2^53 - 1
+ min_json_float = -float64(1<<53 - 1) //-9007199254740991.0 -2^53 - 1
+)
+
func isFloat64AnInteger(f float64) bool {
- if math.IsNaN(f) || math.IsInf(f, 0) {
+ if math.IsNaN(f) || math.IsInf(f, 0) || f < min_json_float || f > max_json_float {
return false
}