POV-Ray : Newsgroups : povray.general : Function: Problem in Defining : Re: Function: Problem in Defining Server Time
20 Apr 2024 09:58:50 EDT (-0400)
  Re: Function: Problem in Defining  
From: dick balaska
Date: 5 Apr 2018 21:02:06
Message: <5ac6c70e$1@news.povray.org>
On 04/05/2018 12:21 PM, clipka wrote:

>      #declare MySeed = seed(4711);
>      #macro MyRand(Min,Max)
>        // compute stuff
>        #local Rand = rand(MySeed);
>        #local Result = Min + (Max-Min)*Rand;
>        // "return" the computed value
>        Result
>      #end
> 

I wrap the return value in parenthesis. The intent is a little clearer 
in the macro def and may avoid usage problems.

     // "return" the computed value
     (Result)

I know clipka, legally this is not required, because Result is a single 
number. But I tend to do

     #local V=<1,2,3>;
     // "return" the computed value
     (Result+V)

where it is morally (debuggingly?) required.

sven, this is because when you use it, think of the expansion.

     #local R = MyRand(low, high) * 2;

which without parens, is
     #local R = Result + V * 2

which of course evaluates as
     #local R = Result + (V * 2)

which is not at all what you want.  With the parens, you get
     #local R = (Result + V) * 2

which is the intent of your usage.

-- 
dik
Rendered 328976 of 330000 (99%)


Post a reply to this message

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