Not, not working

Monkey Forums/Monkey Programming/Not, not working

slenkar(Posted 2012) [#1]
Function Main:Int()
If Not 1>2
Print "one is not bigger than 2"
Else
Print "one is bigger than 2"
Endif

End Function

tested in html5


muddy_shoes(Posted 2012) [#2]
If Not (1>2)



c.k.(Posted 2012) [#3]
Here's my take:

It's doing:

If ( Not 1 ) > 2

which is

If 0 > 2

This fixes it:

If Not (1>2)

So, could be a bug, depending on what symbol thingy should take precedence...


Xaron(Posted 2012) [#4]
"Not" is an unary operator while <, >, = ... are not. Unary operators always have priority.


Samah(Posted 2012) [#5]
[monkeycode]If 1 <= 2[/monkeycode]


jpoag(Posted 2012) [#6]
c.k. is right

Also note that 'Not' evaluates to a Boolean type. That means you can put any number there you want except zero and the result will always be the same.

So really, it's

[monkeycode]
If Not 1>2 'original
If (Not 1) > 2 'unary precedence
If false > 2 'NOT forces Boolean
If 0 > 2 'Compare operator casts to Int()[/monkeycode]

And then the whole thing is optimized out because both sides of the operator are constant expressions.


Floyd(Posted 2012) [#7]
This seems to be the Precedence Table, although the docs don't call it that.

Operators within a block have the same precedence, such as
+	Unary plus
-	Unary minus
~	Bitwise complement
Not	Boolean inverse
with blocks higher in the table having higher precedence.