POV-Ray : Newsgroups : povray.newusers : question about user defined float functions Server Time
20 Jul 2024 00:15:06 EDT (-0400)
  question about user defined float functions (Message 1 to 4 of 4)  
From: Jonathan Bush
Subject: question about user defined float functions
Date: 31 May 2024 07:15:00
Message: <web.6659b0f23151b3296e558a71fde6c206@news.povray.org>
In the reference manual I do not find a formal definition of a user defined
float function. Instead, several examples are provided. I assumed a conditional
expression could be used to define a function, but apparently I was mistaken. I
get an error "Parse Error: Expected 'operator', ? found instead"

Is there any way to create a float function which is a conditional expression?
Thank you.


Post a reply to this message

From: ingo
Subject: Re: question about user defined float functions
Date: 31 May 2024 08:10:00
Message: <web.6659bde35e4f6a6917bac71e8ffb8ce3@news.povray.org>
"Jonathan Bush" <djb### [at] gmxcom> wrote:
> Is there any way to create a float function which is a conditional expression?
> Thank you.

You may look at: select(A, B, C [,D])

ingo


Post a reply to this message

From: Jonathan Bush
Subject: Re: question about user defined float functions
Date: 31 May 2024 09:50:00
Message: <web.6659d46d5e4f6a696e558a71fde6c206@news.povray.org>
"ingo" <nomail@nomail> wrote:
> "Jonathan Bush" <djb### [at] gmxcom> wrote:
> > Is there any way to create a float function which is a conditional expression?
> > Thank you.
>
> You may look at: select(A, B, C [,D])
>
> ingo

Okay, if I understand this correctly, if the input parameter A is boolean, I can
provide any value I want for B, and C is the value returned when A is false, and
D is the value when A is true. I hope I got that right. Thanks for the tip!


Post a reply to this message

From: William F Pokorny
Subject: Re: question about user defined float functions
Date: 31 May 2024 11:01:58
Message: <6659e666$1@news.povray.org>
On 5/31/24 09:46, Jonathan Bush wrote:
> Okay, if I understand this correctly, if the input parameter A is boolean, I can
> provide any value I want for B, and C is the value returned when A is false, and
> D is the value when A is true. I hope I got that right.

I'll add, folks sometimes lose track of the fact the virtual machine 
(VM) select() functionality is mirrored in the Scene Description 
Language (SDL). In other words, you can test your logic outside of the 
function {} wrapper prior to use in the function itself - or alongside.

Bill P.


//---
#version 3.8;

#declare A=-1;
#declare B=-2;
#declare Z=0;
#declare C=+2;

#declare Fn_select3 = function (_a,_b,_c)    { select(_a,_b,_c) }
#declare Fn_select4 = function (_a,_b,_z,_c) { select(_a,_b,_z,_c) }

#debug concat("A = ",str(A,3,1),"\n")
#debug concat("B = ",str(B,3,1),"\n")
#debug concat("Z = ",str(Z,3,1),"\n")
#debug concat("C = ",str(C,3,1),"\n")
#debug "\n"
#debug concat("select(A,B,C)       = ",str(select(A,B,C),3,1),"\n")
#debug concat("Fn_select3(A,B,C)   = ",str(Fn_select3(A,B,C),3,1),"\n")
#debug "\n"
#debug concat("select(A,B,Z,C)     = ",str(select(A,B,Z,C),3,1),"\n")
#debug concat("Fn_select4(A,B,Z,C) = ",str(Fn_select4(A,B,Z,C),3,1),"\n")
#debug "\n"

#error "Stop early\n"
//---


Post a reply to this message

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