POV-Ray : Newsgroups : povray.general : Function: Making negative numbers positive Server Time
15 May 2024 16:14:04 EDT (-0400)
  Function: Making negative numbers positive (Message 1 to 10 of 33)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Sven Littkowski
Subject: Function: Making negative numbers positive
Date: 24 Nov 2015 20:11:15
Message: <56550ab3@news.povray.org>
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.


Post a reply to this message

From: Todd Carnes
Subject: Re: Function: Making negative numbers positive
Date: 24 Nov 2015 20:40:25
Message: <56551189$1@news.povray.org>
On 2015-11-24 17:11, Sven Littkowski wrote:
> 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.
>

Multiply the number by -1.


Post a reply to this message

From: Ger
Subject: Re: Function: Making negative numbers positive
Date: 24 Nov 2015 20:52:15
Message: <5655144f@news.povray.org>
Sven Littkowski wrote:

> 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.

abs()

-- 

Ger


Post a reply to this message

From: Bald Eagle
Subject: Re: Function: Making negative numbers positive
Date: 24 Nov 2015 22:45:00
Message: <web.56552e907aaf16cc5e7df57c0@news.povray.org>
sqrt(pow(x,2))

;)  :D


Post a reply to this message

From: Alain
Subject: Re: Function: Making negative numbers positive
Date: 26 Nov 2015 23:11:51
Message: <5657d807@news.povray.org>
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


Post a reply to this message

From: Todd Carnes
Subject: Re: Function: Making negative numbers positive
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

From: clipka
Subject: Re: Function: Making negative numbers positive
Date: 27 Nov 2015 05:45:50
Message: <5658345e$1@news.povray.org>
Am 27.11.2015 um 11:40 schrieb Todd Carnes:

> 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.

That's only true if the number in question is known to be negative.

In that case, however, it is easier and more efficient to just use the
unary minus operator:

#declare PositiveNumber = -NegativeNumber;


Post a reply to this message

From: clipka
Subject: Re: Function: Making negative numbers positive
Date: 27 Nov 2015 05:52:24
Message: <565835e8$1@news.povray.org>
Am 27.11.2015 um 05:12 schrieb Alain:

> You can also use the sellect() function:
> #declare Abs = sellect(A, -A, A);

The keyword is actually "select".


Post a reply to this message

From: Stephen
Subject: Re: Function: Making negative numbers positive
Date: 27 Nov 2015 06:16:07
Message: <56583b77$1@news.povray.org>
On 11/27/2015 10:52 AM, clipka wrote:
> Am 27.11.2015 um 05:12 schrieb Alain:
>
>> You can also use the sellect() function:
>> #declare Abs = sellect(A, -A, A);
>
> The keyword is actually "select".
>

There is an 'L of a difference. ;-)

-- 

Regards
     Stephen


Post a reply to this message

From: Todd Carnes
Subject: Re: Function: Making negative numbers positive
Date: 27 Nov 2015 11:20:35
Message: <565882d3$1@news.povray.org>
On 2015-11-27 02:45, clipka wrote:
> That's only true if the number in question is known to be negative.
>

I know, but that was what the OP asked for.

> In that case, however, it is easier and more efficient to just use the
> unary minus operator:
>
> #declare PositiveNumber = -NegativeNumber;

That works too, but then it's really just masking the fact that you are 
doing what I said... i.e. multiplying by -1.

Todd


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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