POV-Ray : Newsgroups : povray.general : Re: Probably been asked... Why no power operator? : Re: Probably been asked... Why no power operator? Server Time
5 Aug 2024 06:14:10 EDT (-0400)
  Re: Probably been asked... Why no power operator?  
From: Warp
Date: 14 Nov 2002 03:46:31
Message: <3dd362e6@news.povray.org>
Slime <slm### [at] slimelandcom> wrote:
> i mean, of *course* -3^2 is -9!

  The factorial of 9? I don't think so. ;)

  But seriously. The problem is with precedence.
  In order to understand the problem, let's think about another operator
and relate it to the unary minus: the multiplication operator.
  Since the unary minus has higher precedence than the multiplication
operator, you can write things like "-2*3" or "3*-2" and they both mean
the same thing (of course multiplication is a bit problematic as an example
because the result of "-2*3" will be the same regardless of the precedence
of the operators).
  It's only consistent that the unary minus has higher precedence than the
power operator as well, as it allows you to write "-2^3" and "2^-3". There's
no mathematical reason for making the unary minus to have a lower precedence
then the power operator.
  What you would have wanted is to make the unary minus to have a lower
precedence. This would make "2^-3" illegal because a higher-precedence
operator needs to be evaluated before the lower-precedence one and in
this case it can't be done.
  Of course you will probably answer that in this case the unary minus should
be evaluated first and then the power operator. This contradicts the order
of evaluation of "-2^3" where you want them to be evaluated the other way
around.

  Of course all this hassle would have been avoided if you just had silently
used "-(2^3)" without complaining... We would still have the power operator. ;)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

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