Is there an integrated function to get the sign of a number?

Hi all,

I am probably missing something basic, but I cannot directly solve it by myself.

My question is about a function to return the sign of a given number, e.g.:

sign(-42) should return -1, sign(42) should return 1.

I cannot find such a fuction in the p5.js reference.

Of course I could devide the number by its absolute value, and build a fuction on my own, but I was just wondering why such basic function is not included in p5.js.

Thanks for a hint and best regards!

Hi @1qayxsw2,

Just use…

Cheers
— mnse

4 Likes

Thx, do I somehow need to include or preload this library? Sorry again for the noob question :blush:

Hi @1qayxsw2,

No! Should be usable as described…

Cheers
— mnse

1 Like

Math is a namespace which has always existed as a JS standard built-in object. Therefore not a library:

1 Like