POV-Ray : Newsgroups : povray.general : Macro problem Server Time
29 Jul 2024 02:32:56 EDT (-0400)
  Macro problem (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: posfan12
Subject: Macro problem
Date: 11 Oct 2013 03:55:01
Message: <web.5257adf44d8f0d3941a177270@news.povray.org>
I'm trying to write a macro that randomly either returns -1 or 1. This is what I
have:

#macro randsign()
 #if (rand(HPlanet_Seed_Value) > 0.5)
  1
 #else
  -1
 #end
#end

However, POVray stops rendering and says "All #declares of float, vector, and
 color require semi-colon ';' at end if the language version is set to 3.5 or
 higher."

What am I doing wrong? Adding the semi-colon causes the scene to quit for other
reasons.


Post a reply to this message

From: posfan12
Subject: Re: Macro problem
Date: 11 Oct 2013 05:25:00
Message: <web.5257c34630eb22c641a177270@news.povray.org>
I'm using RC7 by the way.


"posfan12" <nomail@nomail> wrote:
> I'm trying to write a macro that randomly either returns -1 or 1. This is what I
> have:
>
> #macro randsign()
>  #if (rand(HPlanet_Seed_Value) > 0.5)
>   1
>  #else
>   -1
>  #end
> #end
>
> However, POVray stops rendering and says "All #declares of float, vector, and
>  color require semi-colon ';' at end if the language version is set to 3.5 or
>  higher."
>
> What am I doing wrong? Adding the semi-colon causes the scene to quit for other
> reasons.


Post a reply to this message

From: MichaelJF
Subject: Re: Macro problem
Date: 11 Oct 2013 06:10:01
Message: <web.5257cd4e30eb22c6e83c0f490@news.povray.org>
"posfan12" <nomail@nomail> wrote:
> I'm using RC7 by the way.
>
>
> "posfan12" <nomail@nomail> wrote:
> > I'm trying to write a macro that randomly either returns -1 or 1. This is what I
> > have:
> >
> > #macro randsign()
> >  #if (rand(HPlanet_Seed_Value) > 0.5)
> >   1
> >  #else
> >   -1
> >  #end
> > #end
> >
> > However, POVray stops rendering and says "All #declares of float, vector, and
> >  color require semi-colon ';' at end if the language version is set to 3.5 or
> >  higher."
> >
> > What am I doing wrong? Adding the semi-colon causes the scene to quit for other
> > reasons.

I tried your code, but got no idea about this semi-colon issue.

This one works for me:
#declare Zufall=seed(317);

#macro randsign()
   #local Z1=rand(Zufall)-0.5;
   Z1/abs(Z1)
#end

#declare Count=0;
#while(Count<100)
   #declare ZufallsZahl=randsign();
   #debug concat("Zufallszahl: ",str(ZufallsZahl,8,4),"\n")
   #declare Count=Count+1;
#end

Best regards,
Michael


Post a reply to this message

From: MichaelJF
Subject: Re: Macro problem
Date: 11 Oct 2013 06:15:01
Message: <web.5257ce9030eb22c6e83c0f490@news.povray.org>
"posfan12" <nomail@nomail> wrote:
> I'm using RC7 by the way.
>
>
> "posfan12" <nomail@nomail> wrote:
> > I'm trying to write a macro that randomly either returns -1 or 1. This is what I
> > have:
> >
> > #macro randsign()
> >  #if (rand(HPlanet_Seed_Value) > 0.5)
> >   1
> >  #else
> >   -1
> >  #end
> > #end
> >
> > However, POVray stops rendering and says "All #declares of float, vector, and
> >  color require semi-colon ';' at end if the language version is set to 3.5 or
> >  higher."
> >
> > What am I doing wrong? Adding the semi-colon causes the scene to quit for other
> > reasons.

Better thsi one:

#declare Zufall=seed(317);

#macro randsign()
   #local Z1=rand(Zufall)-0.5;
   #if (Z1=0) Z1=0.1; #end     // avoid division by zero
   Z1/abs(Z1)
#end

#declare Count=0;
#while(Count<100)
   #declare ZufallsZahl=randsign();
   #debug concat("Zufallszahl: ",str(ZufallsZahl,8,4),"\n")
   #declare Count=Count+1;
#end


Post a reply to this message

From: posfan12
Subject: Re: Macro problem
Date: 11 Oct 2013 06:15:01
Message: <web.5257ced630eb22c641a177270@news.povray.org>
"MichaelJF" <mi-### [at] t-onlinede> wrote:
> "posfan12" <nomail@nomail> wrote:
> > I'm using RC7 by the way.
> >
> >
> > "posfan12" <nomail@nomail> wrote:
> > > I'm trying to write a macro that randomly either returns -1 or 1. This is what I
> > > have:
> > >
> > > #macro randsign()
> > >  #if (rand(HPlanet_Seed_Value) > 0.5)
> > >   1
> > >  #else
> > >   -1
> > >  #end
> > > #end
> > >
> > > However, POVray stops rendering and says "All #declares of float, vector, and
> > >  color require semi-colon ';' at end if the language version is set to 3.5 or
> > >  higher."
> > >
> > > What am I doing wrong? Adding the semi-colon causes the scene to quit for other
> > > reasons.
>
> I tried your code, but got no idea about this semi-colon issue.
>
> This one works for me:
> #declare Zufall=seed(317);
>
> #macro randsign()
>    #local Z1=rand(Zufall)-0.5;
>    Z1/abs(Z1)
> #end
>
> #declare Count=0;
> #while(Count<100)
>    #declare ZufallsZahl=randsign();
>    #debug concat("Zufallszahl: ",str(ZufallsZahl,8,4),"\n")
>    #declare Count=Count+1;
> #end
>
> Best regards,
> Michael

Should I file a bug report?


Post a reply to this message

From: MichaelJF
Subject: Re: Macro problem
Date: 11 Oct 2013 06:15:01
Message: <web.5257cef730eb22c6e83c0f490@news.povray.org>
Sorry again:

#declare Zufall=seed(317);

#macro randsign()
   #local Z1=rand(Zufall)-0.5;
   #if (Z1=0) #local Z1=0.1; #end     // avoid division by zero
   Z1/abs(Z1)
#end

#declare Count=0;
#while(Count<100)
   #declare ZufallsZahl=randsign();
   #debug concat("Zufallszahl: ",str(ZufallsZahl,8,4),"\n")
   #declare Count=Count+1;
#end


Post a reply to this message

From: scott
Subject: Re: Macro problem
Date: 11 Oct 2013 06:19:24
Message: <5257d0ac$1@news.povray.org>
> #macro randsign()
>   #if (rand(HPlanet_Seed_Value) > 0.5)
>    1
>   #else
>    -1
>   #end
> #end

It seems you can't do that (IDK why - maybe a bug, or more likely a 
"feature" of the parser). In fact you can't even do this:

#macro A()
#if(true)
1
#end
#end

It doesn't like having anything to return inside a #if within a #macro

A solution is to just use a temporary variable:

#macro randsign()
  #if (rand(HPlanet_Seed_Value) > 0.5)
   #local temp = 1;
  #else
   #local temp = -1;
  #end
  temp
#end


Post a reply to this message

From: MichaelJF
Subject: Re: Macro problem
Date: 11 Oct 2013 06:50:00
Message: <web.5257d79430eb22c6e83c0f490@news.povray.org>
"posfan12" <nomail@nomail> wrote:

>
> Should I file a bug report?

I'm not sure, if it is a bug. May be we both have overlooked something. I wanted
to provide you with a quick workaround.

Best regards,
Michael


Post a reply to this message

From: Warp
Subject: Re: Macro problem
Date: 11 Oct 2013 13:23:48
Message: <52583424@news.povray.org>
posfan12 <nomail@nomail> wrote:
> #macro randsign()
>  #if (rand(HPlanet_Seed_Value) > 0.5)
>   1
>  #else
>   -1
>  #end
> #end

It's not a bug, but by design (even though it might not be intuitive.)

You have to assign the value you want to "return" from the macro to a
local variable and then have the name of that variable as the last thing
in the macro.

-- 
                                                          - Warp


Post a reply to this message

From: Alain
Subject: Re: Macro problem
Date: 11 Oct 2013 13:33:07
Message: <52583653$1@news.povray.org>

> I'm trying to write a macro that randomly either returns -1 or 1. This is what I
> have:
>
> #macro randsign()
>   #if (rand(HPlanet_Seed_Value) > 0.5)
>    1
>   #else
>    -1
>   #end
> #end
>
> However, POVray stops rendering and says "All #declares of float, vector, and
>   color require semi-colon ';' at end if the language version is set to 3.5 or
>   higher."
>
> What am I doing wrong? Adding the semi-colon causes the scene to quit for other
> reasons.
>
>

It may depend on how you call your macro.

You can call it this way:
#declare Var= randsign();

Or edit the macro this way:
#macro randsign()
  #if (rand(HPlanet_Seed_Value) > 0.5)
   1;
  #else
   -1;
  #end
#end

and sue it this way:
#declare Val= randsign()

OR, use it in some calculation:

#declare Val= randsign()* Value;


Alain


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

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