Ticket Created
over 3 years ago

CIQQA-1312

int and logical &&

4.1.3 win/eclipse

var x = 2, y= 4;
if(x)         {LOG.println(true);} else {LOG.println(false);}
if(y)         {LOG.println(true);} else {LOG.println(false);}
if(x && y)    {LOG.println(true);} else {LOG.println(false);}

prints

true
true
false <--- bug

Parents
  • To be clear, you're assuming Monkey C implements "&&" and "||" similarly for numbers, which it doesn't (sadly).

    And javascript doesn't always return the last operand, it does what I described:

    A || B => A ? A : B

    (if A is "truthy", return A, otherwise return B. Javascript also implements short-circuit logic here, meaning that if A is returned, then B is never evaluated)

    e.g.

    Code:

            var x = 254;
            var y = 1;
            System.println("x || y: " + (x || y));
            System.println("y || x: " + (y || x));
            System.println("x | y: " + (x | y));
    Output:
    x || y: 254
    y || x: 1
    x | y: 255
Comment
  • To be clear, you're assuming Monkey C implements "&&" and "||" similarly for numbers, which it doesn't (sadly).

    And javascript doesn't always return the last operand, it does what I described:

    A || B => A ? A : B

    (if A is "truthy", return A, otherwise return B. Javascript also implements short-circuit logic here, meaning that if A is returned, then B is never evaluated)

    e.g.

    Code:

            var x = 254;
            var y = 1;
            System.println("x || y: " + (x || y));
            System.println("y || x: " + (y || x));
            System.println("x | y: " + (x | y));
    Output:
    x || y: 254
    y || x: 1
    x | y: 255
Children
No Data