POV-Ray : Newsgroups : povray.beta-test : Small bug, asking for someone to check on latest RC : Re: Small bug, asking for someone to check on latest RC Server Time
29 Jul 2024 10:29:19 EDT (-0400)
  Re: Small bug, asking for someone to check on latest RC  
From: Thorsten Froehlich
Date: 26 May 2002 17:51:35
Message: <3cf158e7@news.povray.org>
In article <3cf12a57$1@news.povray.org> , "Anders K." <and### [at] prostard2gcom>
wrote:

>> It still writes '1.0', but this is intended behavior IIRC, the unary '-'
>> has a higher precedence than the '^'.
>
> This is silly, since for even n, (-x)^n = x^n (and for odd n the precedence
> doesn't make a difference). So there's no reason you would ever want (-x)^n,
> and to write -(x^n) you have to use parentheses. Also, in standard
> mathematical notation, -x^n means -(x^n). IMO, unless there's some kind of
> limitation in the parser that prevents unary operators from having lower
> precedence than binary operators (or something similar), this should be
> changed; the unary + and - operators should have the same precedence as the
> binary ones.

It works as it should and exactly like in all other programming languages
where the unary operators also have higher precedence than all other
operators.  It not only always worked this way in POV-Ray, it is also not a
bug and it will not be changed.

However, more to the point, unary operators have to have higher precedence
than all other operators or expressions turn out unreadable.  Imagine an
expression like (x+++---y) or (x*-y).  If the unary operator had lower
precedence they would be illegal, or at least it would make reading the
expressions much more difficult for a human *and* a computer...

As for the "mathematical notation" argument, the proper interpretation I have
always and everywhere been taught is to place parenthesis around the
statement.  I suppose the question if sign precedence is higher or lower than
the power in such a case seems to be a matter of opinion or common agreements
in certain groups rather than any standard.


    Thorsten


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.