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