Absolute value & signum...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Absolute value & signum...

Dan Zuras 3D

        I didn't see either absolute value or
        signum mentioned anywhere.

        They are easy enough to write.

function absoluteValue(x) = (x < 0)?-x:x;

function signum(x) = (x < 0)?-1:(x > 0)?1:0;

        And easy enough to provide.
        You might want to call them abs & sign.
        They are the more commonly used names.
        Its not important.
        But I found a use for them.

        Just a suggestion,


                        Dan

Reply | Threaded
Open this post in threaded view
|

Re: Absolute value & signum...

kintel
Administrator
On Jul 9, 2010, at 08:00 AM, Dan Zuras 3D wrote:

> function absoluteValue(x) = (x < 0)?-x:x;
>
abs() is a built-in function. I Just added it to the docs as well ;)

> function signum(x) = (x < 0)?-1:(x > 0)?1:0;
>
Added to wishlist.

Thanks for sharing,

~/= Marius

--
We are Elektropeople for a better living.





Reply | Threaded
Open this post in threaded view
|

Re: Absolute value & signum...

Giles Bathgate
On Fri, 2010-07-09 at 10:54 +0200, Marius Kintel wrote:
> > function signum(x) = (x < 0)?-1:(x > 0)?1:0;
> >
> Added to wishlist.

Here is a patch to do it

Regards

Giles



0001-Added-a-sign-function.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Absolute value & signum...

kintel
Administrator
On Jul 9, 2010, at 11:24 AM, Giles Bathgate wrote:

> Here is a patch to do it
>
..and committed :)

~/= Marius

--
We are Elektropeople for a better living.