Skip to content

Commit 3eaf189

Browse files
committed
Allow bitwise operations on floats, according to Spec (and Javascript behavior)
1 parent e8f6d25 commit 3eaf189

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

builtins.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,15 @@ var builtinExponent = liftNumeric(func(f float64) float64 {
478478

479479
func liftBitwise(f func(int64, int64) int64) func(*evaluator, potentialValue, potentialValue) (value, error) {
480480
return func(e *evaluator, xp, yp potentialValue) (value, error) {
481-
x, err := e.evaluateInt64(xp)
481+
x, err := e.evaluateNumber(xp)
482482
if err != nil {
483483
return nil, err
484484
}
485-
y, err := e.evaluateInt64(yp)
485+
y, err := e.evaluateNumber(yp)
486486
if err != nil {
487487
return nil, err
488488
}
489-
return makeDoubleCheck(e, float64(f(x, y)))
489+
return makeDoubleCheck(e, float64(f(int64(x.value), int64(y.value))))
490490
}
491491
}
492492

evaluator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ func (e *evaluator) getInt64(val value) (int64, error) {
110110
if err != nil {
111111
return 0, err
112112
}
113-
// We conservatively convert ot int32, so that it can be machine-sized int
114-
// on any machine. And it's used only for indexing anyway.
115113
intNum := int64(num.value)
116114
if float64(intNum) != num.value {
117115
return 0, e.Error(fmt.Sprintf("Expected an integer, but got %v", num.value))

testdata/bitwise_and3.golden

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
RUNTIME ERROR: Expected an integer, but got 1e+30
2-
-------------------------------------------------
3-
testdata/bitwise_and3:1:1-10 $
4-
5-
1e30 & 42
6-
7-
-------------------------------------------------
8-
During evaluation
9-
10-
1+
0

0 commit comments

Comments
 (0)