![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | OgGhostJelly |
How do I get the sign of a float? for example -1
would be "-"
and 1
would be "+"
.
Godot has a built-in sign()
function but It doesn’t work if the number is -0
. sign(-0)
will be 0 and sign(0)
will still be 0, so I can’t detect it.
Is there any bitwise operator or something that will allow me to get the sign of the number?
I found a hacky way of doing this by doing str(n)[0] == "-"
. Gets the first character of n
. If it is "-"
then return true
OgGhostJelly | 2023-05-16 04:28
I’m curious why the sign of zero matters to you. Not saying it shouldn’t / doesn’t - just not sure what the use-case would be…
jgodfrey | 2023-05-16 16:55
I was using some code to detect when a vector is in between the angle that two other vectors make and it would not detect whenever there was a negative zero.
I was using it to track which side a cube is facing, so 0 (right side) and -0 (left side) is a big difference.
Edit: nvm I can just use dot method to get the dot product I didnt need to do all that wierd vector stuff
OgGhostJelly | 2023-05-17 01:54
As far as gdscript is concerned 0
and -0
are exactly the same value, so I don’t really understand the above.
print(0 == -0)
# prints True
jgodfrey | 2023-05-17 02:10