crypto icon indicating copy to clipboard operation
crypto copied to clipboard

Wrong precedence for negative sign in front of a value on a expression

Open lvcabral opened this issue 4 years ago • 2 comments

Try the code below:

Sub Main() 
    x = 96
    y = 56
    w = 1088
    h = 608
    Offset(-x + 96, -y + 56, -w + 1088, -h + 608)
End Sub
Sub Offset(x, y, w, h)
    print x, y, w, h
End Sub

This should print: 0 0 0 0 instead it prints: -192 -112 -2176 -1216

lvcabral avatar Jun 17 '21 21:06 lvcabral

This was introduced recently, the root cause was this pull request: https://github.com/sjbarag/brs/pull/443

lvcabral avatar Jun 17 '21 21:06 lvcabral

It is wrong for any case with negative number first, like the example below:

Off-Roku BrightScript interpreter [Version 0.44.0]

brs> print -1000 + 1000
-2000
brs> print +1000 - 1000
0

lvcabral avatar Jun 17 '21 21:06 lvcabral