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

**URL:** https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658
**Category:** Beginners
**Created:** [August 28, 2023, 10:49am UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658 "2023-08-28T10:49:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![1qayxsw2](https://avatars.discourse-cdn.com/v4/letter/1/f6c823/32.png) [@1qayxsw2](https://discourse.processing.org/u/1qayxsw2)
#### Post date: [August 28, 2023, 10:49am UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658/1 "2023-08-28T10:49:25Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 28, 2023, 11:12am UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658/2 "2023-08-28T11:12:28Z")

</div>

Hi @1qayxsw2,

Just use…

> **[Math.sign() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign?retiredLocale=de)**
>
> The Math.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![1qayxsw2](https://avatars.discourse-cdn.com/v4/letter/1/f6c823/32.png) [@1qayxsw2](https://discourse.processing.org/u/1qayxsw2)
#### Post date: [August 28, 2023, 1:36pm UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658/3 "2023-08-28T13:36:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 28, 2023, 1:44pm UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658/4 "2023-08-28T13:44:36Z")

</div>

Hi @1qayxsw2,

No! Should be usable as described…

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 28, 2023, 8:10pm UTC](https://discourse.processing.org/t/is-there-an-integrated-function-to-get-the-sign-of-a-number/42658/5 "2023-08-28T20:10:10Z")

</div>

> [@1qayxsw2](#):
>
> Thx, do I somehow need to include or preload this library?

[Math](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) is a namespace which has always existed as a JS standard built-in object. Therefore not a library:

> **[Standard built-in objects - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#numbers_and_dates)**
>
> This chapter documents all of JavaScript's standard, built-in objects, including their methods and properties.
