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 12:21:05 EDT (-0400)
  Re: Probably been asked... Why no power operator?  
From: gilroy
Date: 14 Nov 2002 23:20:05
Message: <web.3dd46f2ec24ffac8749cd9ce0@news.povray.org>
Christopher James Huff wrote:
>In article <3dd3cb3c$1[at]news.povray.org>, "Slime" <slm### [at] slimelandcom>
>wrote:
>
>> Well, to say there's no mathematical reason doesn't seem entirely correct.
>> Most everyone is taught that exponentiation comes before negation in an
>> early algebra class. It's the way we've been taught to think.
>
>Um, no. In algebra, there is no precedence, the exponent is in
>superscript, so there is no ambiguity. A plain text programming language
>doesn't have this, an operator has to be used, so it has to pick a
>precedence. I don't know what you were taught...

I'm not sure I understand.  If I read - 2 sup 3, I would interpret it as -(2
sup 3) = -8, just like 4 - x^3 would mean "four minus the cube of x" and
not "four plus the cube of minus x".  And I am not symbolic expert but I've
done my fair share of heavy lifting in mathematics.  I'm pretty sure many,
if not most, people would read it the same way.

On the other hand, if the issue is the parsing of 2^-3, I can see a problem.
 Since in algebra it's a real superscript, it's clear this would be "two to
the power of minus 3", but to a computer parsing plaintext, it's awkward.
Does - bind more tightly than ^?  I can see the issue.  But I'm not sure I
agree with the "solution".

The simplest way out would seem, to my eye, to disallow 2^-3 -- make it a
syntax error for ^ to be followed by anything but a number, an identifier,
or a parenthesis.  It would be annoying, when one used "2^-3" to have to
check the documentation and to have to learn a "different" way of seeing
things.  But that's much preferable to stripping out a useful operator and
cluttering up lines and lines of scene code.  If it's a little harder for
the computer, or a little harder for humans, shouldn't the humans win?

>
>
>> Besides, I would think that since we're adding ^ as a new operator, we could
>> give it whatever precedence we wanted, and it just seems more logical to me
>> to make it work the way we've been taught it should work than to allow the
>> 2^-3 syntax just for convenience.
>
>Not for convenience, for self consistency. There isn't an existing rule,
>so the one that was most logical and consistent was chosen.
>
>Christopher James Huff <cja### [at] earthlinknet>
>http://home.earthlink.net/~cjameshuff/
>POV-Ray TAG: chr### [at] tagpovrayorg
>http://tag.povray.org/
>


Post a reply to this message

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