Skip to content

Commit

Permalink
Deal with deprecated negative operands. (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss authored Feb 14, 2023
1 parent 389f6c3 commit 26bb83c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 17 deletions.
9 changes: 4 additions & 5 deletions clvm/more_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,13 @@ def op_div(args):
(i0, l0), (i1, l1) = args_as_int_list("/", args, 2)
if i1 == 0:
raise EvalError("div with 0", args.to(i0))

if i0 < 0 or i1 < 0:
raise EvalError("div operator with negative operands is deprecated", args)

cost += (l0 + l1) * DIV_COST_PER_BYTE
q, r = divmod(i0, i1)

# this is to preserve a buggy behavior from the initial implementation
# of this operator.
if q == -1 and r != 0:
q += 1

return malloc_cost(cost, args.to(q))


Expand Down
3 changes: 1 addition & 2 deletions tests/brun/div-2.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
brun -c '(/ 2 5)' '(-80001 73)'
cost = 1125
-1096
FAIL: div operator with negative operands is deprecated (0xfec77f 73)
3 changes: 1 addition & 2 deletions tests/brun/div-3.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
brun -c '(/ 2 5)' '(80001 -73)'
cost = 1125
-1096
FAIL: div operator with negative operands is deprecated (0x013881 -73)
3 changes: 1 addition & 2 deletions tests/brun/div-7.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
brun -c '(/ (q . -3) (q . 10))'
cost = 1037
()
FAIL: div operator with negative operands is deprecated (-3 10)
3 changes: 1 addition & 2 deletions tests/brun/div-8.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
brun -c '(/ (q . 3) (q . -10))'
cost = 1037
()
FAIL: div operator with negative operands is deprecated (i -10)
3 changes: 1 addition & 2 deletions tests/brun/div-9.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
brun -c '(/ (q . -3) (q . -10))'
cost = 1037
()
FAIL: div operator with negative operands is deprecated (-3 -10)
2 changes: 1 addition & 1 deletion tests/edge-cases/div-07.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
brun '(/ (q . 0xffff) (q . 0xffff))'
1
FAIL: div operator with negative operands is deprecated (0xffff 0xffff)
2 changes: 1 addition & 1 deletion tests/edge-cases/div-09.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
brun '(/ (q . -1) (q . -1))'
1
FAIL: div operator with negative operands is deprecated (-1 -1)

0 comments on commit 26bb83c

Please sign in to comment.