(no subject)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

XenoLiz
ï
Hm.
|   Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
|    > two,m_two=2,-2 print(-2^2, -two^2, m_two^2)
|    -4      -4      4
 
Why was over estimated priority?
Reply | Threaded
Open this post in threaded view
|

Re:

Ralph Hempel
XenoLiz wrote:
Hm.
|   Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
|    > two,m_two=2,-2 print(-2^2, -two^2, m_two^2)
|    -4      -4      4
Why was over estimated priority?

because ^ binds higher than - and you are calculating

-(2^2) which is now and has always been -4

Ralph

Reply | Threaded
Open this post in threaded view
|

Re:

KHMan
Ralph Hempel wrote:
> XenoLiz wrote:
>> Hm.
>> |   Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
>> |    > two,m_two=2,-2 print(-2^2, -two^2, m_two^2)
>> |    -4      -4      4
>>  
>> Why was over estimated priority?
> 
> because ^ binds higher than - and you are calculating
> 
> -(2^2) which is now and has always been -4

Also, the negative sign should always be considered a unary
operator, (and the only thing with a higher priority is ^) not the
negative sign of a negative number.

-- 
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia