Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sjsonnet/src/sjsonnet/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,10 @@ class Evaluator(
val ll = visitExprAsDouble(e.lhs).toSafeLong(pos)
val rr = visitExprAsDouble(e.rhs).toSafeLong(pos)
if (rr < 0) Error.fail("Shift by negative exponent", pos)
if (rr >= 1 && math.abs(ll) >= (1L << (63 - rr)))
val masked = (rr % 64).toInt
if (masked >= 1 && math.abs(ll) >= (1L << (63 - masked)))
Error.fail("Numeric value outside safe integer range for bitwise operation", pos)
(ll << rr).toDouble
(ll << masked).toDouble
case Expr.BinaryOp.OP_>> =>
val ll = visitExprAsDouble(e.lhs).toSafeLong(pos)
val rr = visitExprAsDouble(e.rhs).toSafeLong(pos)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
std.assertEqual((1 << 64) * 1, 1) &&
std.assertEqual(((1 << 64) + 0) * 1, 1) &&
std.assertEqual((1 << 65) * 1, 2) &&
std.assertEqual((1 << 128) * 1, 1) &&
std.assertEqual((0 << 128) * 1, 0) &&
std.assertEqual(((-1) << 64) * 1, -1) &&
std.assertEqual(((-2) << 65) * 1, -4) &&
std.assertEqual(((-3) << 128) * 1, -3) &&
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Loading