POV-Ray : Newsgroups : povray.general : Whats up with ^ and sqr()? Server Time
27 Nov 2024 08:32:47 EST (-0500)
  Whats up with ^ and sqr()? (Message 1 to 7 of 7)  
From: [GDS|Entropy]
Subject: Whats up with ^ and sqr()?
Date: 8 Feb 2009 03:13:16
Message: <498e941c$1@news.povray.org>
Does anyone know what ^ and sqr() have turned into?
Please don't say I have to do this: (foo)*(foo), that would just be dumb, 
and terribly annoying...

I love ^....why in the nine hells did they ditch it anyway?

thanks,
ian


Post a reply to this message

From: Stephen
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 03:41:31
Message: <ti6to4die0j9trh7n4j16hro8d2ievv1vd@4ax.com>
On Sun, 8 Feb 2009 03:13:15 -0500, "[GDS|Entropy]" <gds### [at] hotmailcom>
wrote:

>Does anyone know what ^ and sqr() have turned into?


pwr(x,y) and sqrt(A)
-- 

Regards
     Stephen


Post a reply to this message

From: Warp
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 03:52:29
Message: <498e9d4d@news.povray.org>
Stephen <mcavoysAT@aoldotcom> wrote:
> pwr(x,y)

  Don't you mean pow(x,y)?

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 04:07:21
Message: <498ea0c9@news.povray.org>
[GDS|Entropy] <gds### [at] hotmailcom> wrote:
> I love ^....why in the nine hells did they ditch it anyway?

  The problem with the operator ^ in scripting languages which are by
necessity ascii-based is that its interpretation is ambiguous.

  In contrast with other binary operators, such as - and /, where it's
clear that the precedence is left-to-right, the same is not so clear for
the binary operator ^.

  By "left-to-right precedence" I mean that, for example "2-3-4" is
interpreted as "(2-3)-4" and not as "2-(3-4)". Likewise for "2/3/4".

  With ^ the interpretation becomes more difficult. Should "2^3^4" be
interpreted as "(2^3)^4" or as "2^(3^4)"? Needless to say that these two
interpretations give different results (4096 vs 2417851639229258349412352).

  There are two possible arguments in this:

1) Operator ^ should work in the same way as all the other binary operators,
for consistency. Thus it should be interpreted as "(2^3)^4".

2) Operator ^ actually denotes the "superscript" of mathematical formulae,
which means that "2^3^4" is actually "2 superscript 3 superscript 4", which
in mathematics is interpreted as "2^(3^4)".

  The most common interpretation in languages out there (which support
operator ^ as the power operator) is #2, but it's not a writte-in-stone
rule.

  Another problem is the interpretation of the unary minus alongside the
binary operator ^.

  The unary minus has higher precedence than any other operator, which
means that "2^-3" is not a syntax error (because "-3" has higher precedence
than the "^").

  However, if the unary minus has higher precendence than ^, then it causes
another interpretation problem: More specifically "-3^2" would be interpreted
as "(-3)^2", which results in 9. However, the most commonly assumed result
of "-3^2" is -9. In other words, it's usually assumed that the unary minus
in front of a power operation has lower precedence.

  It is perfectly possible (end eg. with a recursive descent parser fairly
trivial) to parse an expression like "-2^-3^-4" as "-(2^(-3^(-4)))", but
it's still a question of definition whether that's really the "correct"
interpretation (because there is no such a thing as "correct" in this case,
as there's no universal rule).

  Personally I wouldn't mind if POV-Ray supported the binary ^ operator
with those precedence rules, but the pov-team has decided to not to take
a stance on this subject, and instead prefer the completely unambiguous
pow(x,y) function.

-- 
                                                          - Warp


Post a reply to this message

From: [GDS|Entropy]
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 05:16:26
Message: <498eb0fa$1@news.povray.org>
X_x'

Well, that is definately the answer to "why not" that I was looking for, and 
it makes sense now that they took the course they did.

What is your website warp? I lost that address a few years ago.

thanks,
ian

"Warp" <war### [at] tagpovrayorg> wrote in message 
news:498ea0c9@news.povray.org...
> [GDS|Entropy] <gds### [at] hotmailcom> wrote:
>> I love ^....why in the nine hells did they ditch it anyway?
>
>  The problem with the operator ^ in scripting languages which are by
> necessity ascii-based is that its interpretation is ambiguous.
>
>  In contrast with other binary operators, such as - and /, where it's
> clear that the precedence is left-to-right, the same is not so clear for
> the binary operator ^.
>
>  By "left-to-right precedence" I mean that, for example "2-3-4" is
> interpreted as "(2-3)-4" and not as "2-(3-4)". Likewise for "2/3/4".
>
>  With ^ the interpretation becomes more difficult. Should "2^3^4" be
> interpreted as "(2^3)^4" or as "2^(3^4)"? Needless to say that these two
> interpretations give different results (4096 vs 
> 2417851639229258349412352).
>
>  There are two possible arguments in this:
>
> 1) Operator ^ should work in the same way as all the other binary 
> operators,
> for consistency. Thus it should be interpreted as "(2^3)^4".
>
> 2) Operator ^ actually denotes the "superscript" of mathematical formulae,
> which means that "2^3^4" is actually "2 superscript 3 superscript 4", 
> which
> in mathematics is interpreted as "2^(3^4)".
>
>  The most common interpretation in languages out there (which support
> operator ^ as the power operator) is #2, but it's not a writte-in-stone
> rule.
>
>  Another problem is the interpretation of the unary minus alongside the
> binary operator ^.
>
>  The unary minus has higher precedence than any other operator, which
> means that "2^-3" is not a syntax error (because "-3" has higher 
> precedence
> than the "^").
>
>  However, if the unary minus has higher precendence than ^, then it causes
> another interpretation problem: More specifically "-3^2" would be 
> interpreted
> as "(-3)^2", which results in 9. However, the most commonly assumed result
> of "-3^2" is -9. In other words, it's usually assumed that the unary minus
> in front of a power operation has lower precedence.
>
>  It is perfectly possible (end eg. with a recursive descent parser fairly
> trivial) to parse an expression like "-2^-3^-4" as "-(2^(-3^(-4)))", but
> it's still a question of definition whether that's really the "correct"
> interpretation (because there is no such a thing as "correct" in this 
> case,
> as there's no universal rule).
>
>  Personally I wouldn't mind if POV-Ray supported the binary ^ operator
> with those precedence rules, but the pov-team has decided to not to take
> a stance on this subject, and instead prefer the completely unambiguous
> pow(x,y) function.
>
> -- 
>                                                          - Warp
>


Post a reply to this message

From: Stephen
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 05:26:52
Message: <vpcto4p93of8dkkmvtvghsha25geodvjhr@4ax.com>
On 8 Feb 2009 03:52:29 -0500, Warp <war### [at] tagpovrayorg> wrote:

>Stephen <mcavoysAT@aoldotcom> wrote:
>> pwr(x,y)
>
>  Don't you mean pow(x,y)?

Yes, I'm getting old and my sight is not what it was ;)

pwr(x,y)  is "h raised to the complex power x+iy" in the Julia Fractal settings.
-- 

Regards
     Stephen


Post a reply to this message

From: Warp
Subject: Re: Whats up with ^ and sqr()?
Date: 8 Feb 2009 06:39:51
Message: <498ec487@news.povray.org>
[GDS|Entropy] <gds### [at] hotmailcom> wrote:
> What is your website warp? I lost that address a few years ago.

  http://iki.fi/warp/ will do.

-- 
                                                          - Warp


Post a reply to this message

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