mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 17:01:02 +02:00
Allow bitwise operations on floats, according to Spec (and Javascript behavior)
This commit is contained in:
parent
e8f6d25f61
commit
3eaf189897
@ -478,15 +478,15 @@ var builtinExponent = liftNumeric(func(f float64) float64 {
|
||||
|
||||
func liftBitwise(f func(int64, int64) int64) func(*evaluator, potentialValue, potentialValue) (value, error) {
|
||||
return func(e *evaluator, xp, yp potentialValue) (value, error) {
|
||||
x, err := e.evaluateInt64(xp)
|
||||
x, err := e.evaluateNumber(xp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
y, err := e.evaluateInt64(yp)
|
||||
y, err := e.evaluateNumber(yp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return makeDoubleCheck(e, float64(f(x, y)))
|
||||
return makeDoubleCheck(e, float64(f(int64(x.value), int64(y.value))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,6 @@ func (e *evaluator) getInt64(val value) (int64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// We conservatively convert ot int32, so that it can be machine-sized int
|
||||
// on any machine. And it's used only for indexing anyway.
|
||||
intNum := int64(num.value)
|
||||
if float64(intNum) != num.value {
|
||||
return 0, e.Error(fmt.Sprintf("Expected an integer, but got %v", num.value))
|
||||
|
11
testdata/bitwise_and3.golden
vendored
11
testdata/bitwise_and3.golden
vendored
@ -1,10 +1 @@
|
||||
RUNTIME ERROR: Expected an integer, but got 1e+30
|
||||
-------------------------------------------------
|
||||
testdata/bitwise_and3:1:1-10 $
|
||||
|
||||
1e30 & 42
|
||||
|
||||
-------------------------------------------------
|
||||
During evaluation
|
||||
|
||||
|
||||
0
|
||||
|
Loading…
x
Reference in New Issue
Block a user