Does Julia have a simple way to check the sign of a number? Something like:
sign(-4) = -1
sign(4) = 1
Does Julia have a simple way to check the sign of a number? Something like:
sign(-4) = -1
sign(4) = 1
That function exists with that name, no?
You can try searching the docs, e.g. Search · The Julia Language, they are sometimes not great but here the third answer is to the function Numbers · The Julia Language and the fourth is to the section Mathematical Operations and Elementary Functions · The Julia Language
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…
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])
If the code you tried is exactly what you posted, that was not comparison (==
) but assignment (=
). That would explain the errors you saw.