POV-Ray : Newsgroups : povray.general : Function: Making negative numbers positive : Re: Function: Making negative numbers positive Server Time
10 Jun 2024 16:11:52 EDT (-0400)
  Re: Function: Making negative numbers positive  
From: Todd Carnes
Date: 27 Nov 2015 05:40:38
Message: <56583326$1@news.povray.org>
On 2015-11-26 20:12, Alain wrote:
> Le 15-11-24 20:11, Sven Littkowski a écrit :
>> Hi.
>>
>> Is there a POV-Ray function that allows to make a negative number to a
>> positive number? I want to use such a function, to make a coordinate
>> number to a positive number. Thanks.
>>
>
> That's the absolute value. The abs() function does exactly what you want.
>  From the documentation:
> Abs
> Absolute value of A. If A is negative, returns -A otherwise returns A.
>
> #declare Abs = abs(A);
>
> A convoluted, and slow, way is to take the square root of the squared
> value:
> #declare Abs = sqrt(pow(x,2));
>
> You can also use the sellect() function:
> #declare Abs = sellect(A, -A, A);
>
> Or use an #if...#else...#end test:
> #declare Abs = #if(A<0) -A; #lese A; #end
> or
> #if(A<0) #declare Abs = -A; #elese #declare Abs = A; #end
>
> If you search and experiment, you may find some other ways to do the same.
>
>
>
>
> Alain

Why use a function at all? If you want to change a negative number to a 
positive number all you have to do is multiply it by -1.


Post a reply to this message

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