Skip to content

Commit db0af9b

Browse files
authored
Merge pull request kubernetes#128099 from benluddy/nested-number-as-float64-portability
Make NestedNumberAsFloat64 accuracy test architecture-neutral.
2 parents 9b56413 + e413e02 commit db0af9b

File tree

1 file changed

+4
-2
lines changed
  • staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured

1 file changed

+4
-2
lines changed

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
gojson "encoding/json"
2121
"fmt"
2222
"io"
23+
"math/big"
2324
"strings"
2425

2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -136,10 +137,11 @@ func NestedNumberAsFloat64(obj map[string]interface{}, fields ...string) (float6
136137
}
137138
switch x := val.(type) {
138139
case int64:
139-
if x != int64(float64(x)) {
140+
f, accuracy := big.NewInt(x).Float64()
141+
if accuracy != big.Exact {
140142
return 0, false, fmt.Errorf("%v accessor error: int64 value %v cannot be losslessly converted to float64", jsonPath(fields), x)
141143
}
142-
return float64(x), true, nil
144+
return f, true, nil
143145
case float64:
144146
return x, true, nil
145147
default:

0 commit comments

Comments
 (0)