POV-Ray : Newsgroups : povray.general : A macro that drops a vector-- what's the syntax again? Server Time
1 Aug 2024 14:35:04 EDT (-0400)
  A macro that drops a vector-- what's the syntax again? (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 11:57:46
Message: <43737c09@news.povray.org>
Zeger Knaepen <zeg### [at] povplacecom> wrote:
> what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?

  Look at his "sign" implementation. It's abs().

-- 
                                                          - Warp


Post a reply to this message

From: John VanSickle
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 19:14:32
Message: <4373e268@news.povray.org>
Zeger Knaepen wrote:

> "kurtz le pirate" <kur### [at] yahoofr> wrote in message
news:kurtzlepirate-B61563.07015210112005@news.povray.org...
> 
>>In article <4372b765@news.povray.org>,
>> "Greg M. Johnson" <p t e r a n d o n @ 
>> thecommononethatstartswithY.com> wrote:
>>
>>::I cannot get the following code to work:
>>::
>>:://-----------------------------
>>::#macro sign(a)
>>::#if (a<0)
>>::        (-a)
>>::#else
>>::        (a)
>>::#end
>>::#end
>>
>>... abs() already exist in pov
> 
> 
> what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?

With a divide-by-zero error when x==0.

Regards,
John


Post a reply to this message

From: John VanSickle
Subject: Has this bug been reported?
Date: 11 Nov 2005 17:32:03
Message: <43751be3$1@news.povray.org>
Greg M. Johnson wrote:

> I cannot get the following code to work:
> 
> //-----------------------------
> #macro sign(a)
> #if (a<0)
>         (-a)
> #else
>         (a)
> #end
> #end

I've noticed that this way of using macros to express things leads to 
parse errors.  There is a work-around (which has already been posted), 
but the docs give no reason for this construction to fail.  Is this 
behavior deemed worthy of correction?

Regards,
John


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Has this bug been reported?
Date: 11 Nov 2005 18:12:00
Message: <43752540$1@news.povray.org>
John VanSickle wrote:
> Greg M. Johnson wrote:
> 
>> I cannot get the following code to work:
>>
>> //-----------------------------
>> #macro sign(a)
>> #if (a<0)
>>         (-a)
>> #else
>>         (a)
>> #end
>> #end
> 
> I've noticed that this way of using macros to express things leads to 
> parse errors.  There is a work-around (which has already been posted), 
> but the docs give no reason for this construction to fail.

Well, they do, but I agree it could be a lot clearer.  In "Are POV-Ray 
Macros a Function or a Macro?" it explains it:

"When the body of a macro consists of statements that create an entire item 
such as an object, texture, etc. then the macro acts like a function which 
returns a single value."

The "statements that create an entire item" is the important part here. What 
the macro above is are *two* statements that create *two* items.  Basically, 
the word "item" means what is best explained as "evereything you could also 
assign to a single #declared variable".

> Is this behavior deemed worthy of correction?

It is correct, and it is also possible to obey the "one statement" rule! :-) 
  It just requires slightly different syntax:

#macro sign(a)
(
#if (a<0)
         -a
#else
         a
#end
);
#end

is perfectly legal!

	Thorsten


Post a reply to this message

From: Greg M  Johnson
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 11 Nov 2005 21:40:16
Message: <43755610@news.povray.org>
Greg M. Johnson wrote:


 Oi vey!  Too much late-night coding, I guess.  :-S

Yes, that's an abs() function.  I wanted a sign() function and so was
writing my own.

Perhaps it was late-night delusions, but I did think that povray 3.5 (the
apt-get version) was freaking with me when it came to nested function/macro
calls. 


> I cannot get the following code to work:
> 
> //-----------------------------
> #macro sign(a)
> #if (a<0)
>         (-a)
> #else
>         (a)
> #end
> #end


Post a reply to this message

From: Warp
Subject: Re: Has this bug been reported?
Date: 12 Nov 2005 03:09:05
Message: <4375a321@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> I've noticed that this way of using macros to express things leads to 
> parse errors.  There is a work-around (which has already been posted), 
> but the docs give no reason for this construction to fail.  Is this 
> behavior deemed worthy of correction?

  The documentation could be clearer. It's difficult to explain clearly,
though. Any suggestions?
  The behaviour itself is logical, but not easy to explain.

-- 
                                                          - Warp


Post a reply to this message

From: John VanSickle
Subject: Re: Has this bug been reported?
Date: 12 Nov 2005 11:15:01
Message: <43761505$1@news.povray.org>
Thorsten Froehlich wrote:

> John VanSickle wrote:
> 
>> Greg M. Johnson wrote:
>>
>>> I cannot get the following code to work:
>>>
>>> //-----------------------------
>>> #macro sign(a)
>>> #if (a<0)
>>>         (-a)
>>> #else
>>>         (a)
>>> #end
>>> #end
>>
>>
>> I've noticed that this way of using macros to express things leads to 
>> parse errors.  There is a work-around (which has already been posted), 
>> but the docs give no reason for this construction to fail.
> 
> 
> Well, they do, but I agree it could be a lot clearer.  In "Are POV-Ray 
> Macros a Function or a Macro?" it explains it:
> 
> "When the body of a macro consists of statements that create an entire 
> item such as an object, texture, etc. then the macro acts like a 
> function which returns a single value."
> 
> The "statements that create an entire item" is the important part here. 
> What the macro above is are *two* statements that create *two* items.  
> Basically, the word "item" means what is best explained as "evereything 
> you could also assign to a single #declared variable".
> 
>> Is this behavior deemed worthy of correction?
> 
> 
> It is correct, and it is also possible to obey the "one statement" rule! 
> :-)  It just requires slightly different syntax:
> 
> #macro sign(a)
> (
> #if (a<0)
>         -a
> #else
>         a
> #end
> );
> #end
> 
> is perfectly legal!

Okay.  I was already using the work-around.

Regards,
John


Post a reply to this message

From: Alain
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 12 Nov 2005 14:44:51
Message: <43764633$1@news.povray.org>
Greg M. Johnson nous apporta ses lumieres en ce 2005-11-11 21:39:
> Greg M. Johnson wrote:
> 
> 
>  Oi vey!  Too much late-night coding, I guess.  :-S
> 
> Yes, that's an abs() function.  I wanted a sign() function and so was
> writing my own.
> 
> Perhaps it was late-night delusions, but I did think that povray 3.5 (the
> apt-get version) was freaking with me when it came to nested function/macro
> calls. 
> 
> 
> 
>>I cannot get the following code to work:
>>
>>//-----------------------------
>>#macro sign(a)
>>#if (a<0)
>>        (-a)
>>#else
>>        (a)
>>#end
>>#end
a sign() function return 1 if >0, -1 if <0 and 0 if =0.
It should look like:
#macro sign(a)
#if(a<0) #local S=-1;
  #else #if(a>0) #local S=1;
   #else #local S=0;
   #end
  #end
(S) // return the result
#end

-- 
Alain
-------------------------------------------------
After any salary raise, you will have less money at the end of the month than you did
before.


Post a reply to this message

From: Zeger Knaepen
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 12 Nov 2005 21:37:45
Message: <4376a6f9$1@news.povray.org>
"John VanSickle" <evi### [at] hotmailcom> wrote in message
news:4373e268@news.povray.org...
> >>... abs() already exist in pov
> >
> >
> > what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?
>
> With a divide-by-zero error when x==0.

ah, yes, (x!=0?x/abs(x):0) then!

cu!
--
#macro G(b,e)b+(e-b)*C/50#end#macro _(b,e,k,l)#local C=0;#while(C<50)
sphere{G(b,e)+3*z.1pigment{rgb G(k,l)}finish{ambient 1}}#local C=C+1;
#end#end _(y-x,y,x,x+y)_(y,-x-y,x+y,y)_(-x-y,-y,y,y+z)_(-y,y,y+z,x+y)
_(0x+y.5+y/2x)_(0x-y.5+y/2x)            // ZK http://www.povplace.com


Post a reply to this message

From: Zeger Knaepen
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 12 Nov 2005 21:38:01
Message: <4376a709$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message news:43737c09@news.povray.org...
> Zeger Knaepen <zeg### [at] povplacecom> wrote:
> > what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?
>
>   Look at his "sign" implementation. It's abs().

hmm, you're right :)

cu!
--
#macro G(b,e)b+(e-b)*C/50#end#macro _(b,e,k,l)#local C=0;#while(C<50)
sphere{G(b,e)+3*z.1pigment{rgb G(k,l)}finish{ambient 1}}#local C=C+1;
#end#end _(y-x,y,x,x+y)_(y,-x-y,x+y,y)_(-x-y,-y,y,y+z)_(-y,y,y+z,x+y)
_(0x+y.5+y/2x)_(0x-y.5+y/2x)            // ZK http://www.povplace.com


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

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