lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


XenoLiz wrote:
> |> From: Ralph Hempel <rhempel@hempeldesigngroup.com>
> |> Subject: Re:
> 
> |> 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
> 
> |> From: KHMan <keinhong@gmail.com>
> |> [snip snip]
> |> 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.
> 
> ??...
> I understand, what Lua so doing, I wondered for which Lua this do?
> In 60x-70x the priority of unar Ops( Fortran 6x-7x ) be less then infix Ops
> [was feel it the duty, what it's different positions], and we have this
> artifacts.

Perl and Python also binds ** more strongly than a unary minus.

So I'd just use Lua a little differently compared to how I use
Fortran. In practice, I believe most people will remove doubt by
using parentheses. Sure, all languages have precedence for
operators, but no sane programmer writes complex expressions
without parentheses anyway.

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