# Check the sign of a number

**URL:** <https://discourse.julialang.org/t/check-the-sign-of-a-number/42636>\
**Category:** New to Julia\
**Created:** [July 6, 2020, 8:14pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636 "2020-07-06T20:14:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 6, 2020, 8:14pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/1 "2020-07-06T20:14:38Z")

</div>

Does Julia have a simple way to check the sign of a number? Something like:

```
sign(-4) = -1
sign(4) = 1

```

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [July 6, 2020, 8:17pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/2 "2020-07-06T20:17:31Z")

</div>

That function exists with that name, no?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 6, 2020, 8:20pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/3 "2020-07-06T20:20:30Z")

</div>

> [@Nash](#):
>
> Does Julia have a simple way to check the sign of a number?

You can try searching the docs, e.g. [Search · The Julia Language](https://docs.julialang.org/en/v1/search/?q=sign), they are sometimes not great but here the third answer is to the function [Numbers · The Julia Language](https://docs.julialang.org/en/v1/base/numbers/#Base.signed) and the fourth is to the section [Mathematical Operations and Elementary Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Sign-and-absolute-value-functions-1)

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 6, 2020, 8:23pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/4 "2020-07-06T20:23:07Z")

</div>

That was strange. Somehow my code threw and error when I tried, and I just assumed it it didn’t exist. I should have checked the simple case…

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [July 6, 2020, 9:07pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/5 "2020-07-06T21:07:49Z")

</div>

Note that if you try this on a vector, e.g. sign([1;4]) then you’ll get an error since the correct syntax would be sign.([1;4])

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [July 6, 2020, 9:12pm UTC](https://discourse.julialang.org/t/check-the-sign-of-a-number/42636/6 "2020-07-06T21:12:34Z")

</div>

If the code you tried is exactly what you posted, that was not comparison (`==`) but assignment (`=`). That would explain the errors you saw.
