POV-Ray : Newsgroups : povray.advanced-users : Either pov or Greg fails at simple addition Server Time
1 Nov 2024 19:16:26 EDT (-0400)
  Either pov or Greg fails at simple addition (Message 1 to 4 of 4)  
From: Greg M  Johnson
Subject: Either pov or Greg fails at simple addition
Date: 26 Feb 2001 09:16:44
Message: <3A9A63DE.8B60C9E2@my-dejanews.com>
I declare a macro which returns a float bounded by [-2.0,2.0].
I multiply the value of this macro by  0.05 and add it to 0.91.
What is the upper limit of the sum?

The variable of interest below is "brakepct"

//CODE BELOW HELPS YOU UNDERSTAND MY PREDICAMENT

#declare years=0;
#while(years<1)          //

#declare RRR=seed(years+99+0) ;             //note years+99 is base
#macro rdr()
(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)
#end

#declare wallbraketurns=24.5+18.0*rdr();
#declare wallaccelturns=61.0+30.0*rdr();
#declare carbraketurns= 14.0+8.00*rdr();
#declare caraccelturns= 38.0+18.0*rdr();
#declare steerfactor=   1.20+0.29*rdr();
#declare brakepct=      0.91+0.05*rdr();
#declare accelboost=    0.93+0.41*rdr();
#declare VMAX=          6.60+2.80*rdr();
#declare otherang=      8.00+5.00*rdr();

#debug "\n The value for brakepct is "
#debug str(brakepct,7,4)
#debug "  \n"

#debug "\n brakepct is calculated by 0.91+0.05*rdr()"

// now here's a routine to investigate the upper limit of rdr();

#declare counter=0;
#declare maxrdr=0;
#while(counter<10000)
        #declare n=rdr();
        #if(maxrdr<n)
                #declare maxrdr=n;
        #end
#declare counter=counter+1;
#end

#debug "\n 10000 iterations of rdr meanwhile gives a max of  only :"
#debug str(maxrdr,6,4)
#debug "\n   "
#debug "This value approaches 2.0, the expected value."


#declare brakepct2=      0.91+0.05*maxrdr;
#debug "\n \n So the max value of brakepct should be slightly higher
than:"
#debug str(brakepct2,6,4)
#debug "\n   "

#declare years=years+1;
#end

camera {
  location <0, -65,-0>
  look_at  <0, 0, 0>
  angle 30
}
light_source{<10,-200,50>rgb .2}


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Either pov or Greg fails at simple addition
Date: 26 Feb 2001 09:18:33
Message: <3A9A6455.873339CD@my-dejanews.com>
"Greg M. Johnson" wrote:

> #macro rdr()
> (rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)
> #end

If you replace that macro with this one, the world returns to normal.
WHY!?  Is there an error in what povray (note: using mega 0.6) does with
parens???

// replace with this macro
#macro rdr()
//(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)
rand(RRR)+rand(RRR)+rand(RRR)+rand(RRR)-2
#end


Post a reply to this message

From: Ron Parker
Subject: Re: Either pov or Greg fails at simple addition
Date: 26 Feb 2001 09:27:27
Message: <slrn99kpuh.tal.ron.parker@fwi.com>
On Mon, 26 Feb 2001 09:12:37 -0500, Greg M. Johnson wrote:
>"Greg M. Johnson" wrote:
>
>> #macro rdr()
>> (rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)
>> #end
>
>If you replace that macro with this one, the world returns to normal.

I'll bet it doesn't really.

>WHY!?  Is there an error in what povray (note: using mega 0.6) does with
>parens???

It's not an error, but it might be unexpected if you think macros act like
functions.  This line:

#declare brakepct=      0.91+0.05*rdr();

is parsed as

#declare brakepct=0.91+0.05*(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+
(rand(RRR)-0.5);

As you can see, the .05 only applies to the first term of your addition.
Your macro should read

#macro rdr()
((rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5)+(rand(RRR)-0.5))
#end

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


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Either pov or Greg fails at simple addition
Date: 26 Feb 2001 09:34:28
Message: <3A9A6806.9872A34F@my-dejanews.com>
Ron Parker wrote:

> It's not an error, but it might be unexpected if you think macros act like
> functions.

                   |

            \   ------   /
               /      \
       ---    |        |  ----
              |   OO   |
              \   OO   /
         /     \   |  /  \
                \  | /
                 #####
                 #####
                 #####


Post a reply to this message

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