POV-Ray : Newsgroups : povray.general : unexpected rotation result Server Time
8 Aug 2024 18:15:40 EDT (-0400)
  unexpected rotation result (Message 9 to 18 of 48)  
<<< Previous 8 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Scott Hill
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 11:15:25
Message: <3a7ed19d$1@news.povray.org>
"Tom Melly" <tom### [at] tomandlucouk> wrote in message
news:3a7e8c51@news.povray.org...
> "PoD" <pod### [at] merlinnetau> wrote in message
> news:3A7E8847.C9EFB12A@merlin.net.au...
>
> All in all, it reminds me of what someone at work told me. He is an
> experienced programmer and script writer, but he always uses brackets...
>

    Most experienced programmers/scripters do - it's the safest way to get
any language to do what _you want_, rather than what _it thinks you want_ !
E.g, what does 1+2*3-4 evaluate to ?

Scott.


Post a reply to this message

From: Gail Shaw
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 14:39:50
Message: <3a7f0186@news.povray.org>
Scott Hill <sco### [at] ncgraphicsnet> wrote in message
news:3a7ed19d$1@news.povray.org...
>     Most experienced programmers/scripters do - it's the safest way to get
> any language to do what _you want_, rather than what _it thinks you want_
!
> E.g, what does 1+2*3-4 evaluate to ?
>


If the rules of precedence that I remember are correct then that equals 3,
but it's
not clear from a quick look. I tend to use brackets if there are more that 3
terms
in an expression, regardless of whether they are actually needed or not.

Gail
--
********************************************************************
* gsh### [at] monotixcoza              * System.dat not found.         *
* http://www.rucus.ru.ac.za/~gail/ * Reformat hard drive Y)es O)k  *
********************************************************************
* If at first you don't succeed, call it version 1.0               *
********************************************************************


Post a reply to this message

From: Peter J  Holzer
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 16:01:42
Message: <slrn97u21r.1qn.hjp-usenet@teal.h.hjp.at>
On 2001-02-05 16:14, Scott Hill <sco### [at] ncgraphicsnet> wrote:
>"Tom Melly" <tom### [at] tomandlucouk> wrote in message
>news:3a7e8c51@news.povray.org...
>> "PoD" <pod### [at] merlinnetau> wrote in message
>> news:3A7E8847.C9EFB12A@merlin.net.au...
>>
>> All in all, it reminds me of what someone at work told me. He is
>> an experienced programmer and script writer, but he always uses
>> brackets...
>
>    Most experienced programmers/scripters do - it's the safest way to
>get any language to do what _you want_, rather than what _it thinks you
>want_ ! E.g, what does 1+2*3-4 evaluate to ?

That one should be the same (3) in just about every programming
language. But there are more difficult examples. E.g., what is
(0x11 & 0xF0 == 0x10) in C? C has so many operators that even the
experienced C programmer gets confused sometimes. It gets worse if you
use several programming languages with slightly different evaluation
rules.

However, more parentheses are not always more readable. Where the
average programmer already knows the precedence (e.g, multiplication
before addition), they only clutter the display and make the reader
wonder why they were used. For example, I wouldn't write
    1+(2*3)+4,
although I would probably write 
    1 + 2*3 + 4
to enhance readability for the human reader.

Really religious application of parentheses is required in macro
processors which do simple string substitutions (like cpp or those of
many assemblers). Otherwise you get nasty surprises if you do something
like

#define twice(a) a*2
printf("%d", twice(1+2));

	hp

-- 
   _  | Peter J. Holzer    | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR       | which is our implementation of Linux.
| |   | hjp### [at] wsracat      | 
__/   | http://www.hjp.at/ |	-- Scott McNealy, Dec. 2000


Post a reply to this message

From: Margus Ramst
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 16:27:18
Message: <3a7f1ab6@news.povray.org>
"Peter J. Holzer" <hjp### [at] hjpat> wrote:
> 
> Really religious application of parentheses is required in macro
> processors which do simple string substitutions (like cpp or those of
> many assemblers).

Why go there, just take POV macros for example :)
I encounted several frustrating quirks with POV macros, before I learned to
use parantheses liberally both in macro bodies and around macro calls.

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:09:32
Message: <3A7F3285.CAAFC1FA@faricy.net>
Scott Hill wrote:

>     Most experienced programmers/scripters do - it's the safest way to get
> any language to do what _you want_, rather than what _it thinks you want_ !
> E.g, what does 1+2*3-4 evaluate to ?

3. Bad example, that's standard basic math. Everyone learns order of operations
in elementary school! :) In fact, even with all the computer-specific
extensions like bit rotation and boolean logic, the order of precedence should
still be the same in every language.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:13:59
Message: <3A7F3390.822EA9BB@faricy.net>
"Peter J. Holzer" wrote:

> That one should be the same (3) in just about every programming
> language. But there are more difficult examples. E.g., what is
> (0x11 & 0xF0 == 0x10) in C? C has so many operators that even the
> experienced C programmer gets confused sometimes. It gets worse if you
> use several programming languages with slightly different evaluation
> rules.

True, parentheses can help you be less obfuscated. But I thought all
languages had the same order of operations, except maybe a few very obscure
examples.


> However, more parentheses are not always more readable. Where the
> average programmer already knows the precedence (e.g, multiplication
> before addition), they only clutter the display and make the reader
> wonder why they were used. For example, I wouldn't write
>     1+(2*3)+4,
> although I would probably write
>     1 + 2*3 + 4
> to enhance readability for the human reader.

I find myself doing that more; put a space padding around additive
operations but bunch together multiplicative operations. That shows the
algebraic seperation of terms, which incidentally is also where the parser
should seperate it. So is useful to know. :)


--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Ron Parker
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:53:15
Message: <slrn97uf7e.4fs.ron.parker@fwi.com>
On Mon, 05 Feb 2001 17:13:20 -0600, David Fontaine wrote:
>True, parentheses can help you be less obfuscated. But I thought all
>languages had the same order of operations, except maybe a few very obscure
>examples.

Sometimes the parser has a bug, though.  Not that I'm naming names or
anything.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Mark Wagner
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 01:20:54
Message: <3a7f97c6$1@news.povray.org>
David Fontaine wrote in message <3A7F3390.822EA9BB@faricy.net>...
>
>True, parentheses can help you be less obfuscated. But I thought all
>languages had the same order of operations, except maybe a few very obscure
>examples.


All Reverse Polish Notation languages have the same order of operation:
strictly left-to-right for all operators.

--
Mark


Post a reply to this message

From: John VanSickle
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 01:24:03
Message: <3A7FAE41.E1255D1A@hotmail.com>
Tom Melly wrote:
> 
> I came across this one the other day (don't know how I'd missed this
> "feature" before).
> 
> Basically, I expected the two following rotations to be identical:
> 
> rotate y * - 45 + 45

Which the parser expands to y*-45 + <45,45,45> = <45,0,45>

> rotate y * (- 45 + 45)

Which the parser evaluates as y*0.

> Confused of Putney.

Hope this enlightens,
John


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 07:02:19
Message: <3a7fe7cb@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote in message
news:3A7F3285.CAAFC1FA@faricy.net...
> Scott Hill wrote:
>
> >     Most experienced programmers/scripters do - it's the safest way to
get
> > any language to do what _you want_, rather than what _it thinks you
want_ !
> > E.g, what does 1+2*3-4 evaluate to ?
>
> 3.

    No ! 5.

> Bad example, that's standard basic math. Everyone learns order of
operations
> in elementary school! :) In fact, even with all the computer-specific
> extensions like bit rotation and boolean logic, the order of precedence
should
> still be the same in every language.
>

    That's the point - we and parsers all assume, because we've all learned
(or, in the case of parsers, have been hard coded with) the correct operator
ordering, that it evaluates to 3, but, I may not have meant that, I could
just as easily meant ((1+2)*3)-4 ! Without brackets it is ambiguous, to a
degree - we may default to assuming that we're meant to follow the standard
operator order rules but we don't and can't know that that assumption is
correct.

Scott.


Post a reply to this message

<<< Previous 8 Messages Goto Latest 10 Messages Next 10 Messages >>>

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