![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Zeger Knaepen <zeg### [at] povplace com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Zeger Knaepen wrote:
> "kurtz le pirate" <kur### [at] yahoo fr> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
John VanSickle <evi### [at] hotmail com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"John VanSickle" <evi### [at] hotmail com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"Warp" <war### [at] tag povray org> wrote in message news:43737c09@news.povray.org...
> Zeger Knaepen <zeg### [at] povplace com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |