(f func(int64, int64) int64, positiveRightArg bool)
| 1205 | ) |
| 1206 | |
| 1207 | func liftBitwise(f func(int64, int64) int64, positiveRightArg bool) func(*interpreter, value, value) (value, error) { |
| 1208 | return func(i *interpreter, xv, yv value) (value, error) { |
| 1209 | x, err := i.getNumber(xv) |
| 1210 | if err != nil { |
| 1211 | return nil, err |
| 1212 | } |
| 1213 | y, err := i.getNumber(yv) |
| 1214 | if err != nil { |
| 1215 | return nil, err |
| 1216 | } |
| 1217 | if x.value < minSafeIntValue || x.value > maxSafeIntValue { |
| 1218 | msg := fmt.Sprintf("Bitwise operator argument %v outside of range [%v, %v]", x.value, int64(minSafeIntValue), int64(maxSafeIntValue)) |
| 1219 | return nil, makeRuntimeError(msg, i.getCurrentStackTrace()) |
| 1220 | } |
| 1221 | if y.value < minSafeIntValue || y.value > maxSafeIntValue { |
| 1222 | msg := fmt.Sprintf("Bitwise operator argument %v outside of range [%v, %v]", y.value, int64(minSafeIntValue), int64(maxSafeIntValue)) |
| 1223 | return nil, makeRuntimeError(msg, i.getCurrentStackTrace()) |
| 1224 | } |
| 1225 | if positiveRightArg && y.value < 0 { |
| 1226 | return nil, makeRuntimeError("Shift by negative exponent.", i.getCurrentStackTrace()) |
| 1227 | } |
| 1228 | return makeDoubleCheck(i, float64(f(int64(x.value), int64(y.value)))) |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | var builtinShiftL = liftBitwise(func(x, y int64) int64 { return x << uint(y%64) }, true) |
| 1233 | var builtinShiftR = liftBitwise(func(x, y int64) int64 { return x >> uint(y%64) }, true) |
no test coverage detected
searching dependent graphs…