0 votes

I need to find the sign of a result of a mathematical calculation. It might be either positive or negative. I have found the math function enumerations, and I know that MATH_SIGN is what I am probably looking for. However, in all of my Googling, and searching the forums, I have yet to find an example of how this built in function is used. No example of the syntax. My experimentation has proven useless also. Does anyone know the syntax for using the MATH built in functions?

in Engine by (34 points)

Could you use a simple function for determining the sign? For example:

 func is_negative(number):
    if number < 0:
          return true
          return false

Yes, I could. But what I am trying to do is learn how to use the builtin MATH functions.

Have you tried something like:

var foo = some_function(bar) > 0

This means that the value of foo won't be lesser than 0, even if the returned value of some_function() is lesser than 0.

Never mind, the answer was surprisingly simple once I tracked the sucker down and beat it to the ground! LOL! It's a built in function. All I needed to do was call it by its proper name as described in the GDScript documentation.x = sign(y) will return a 1 if the value is positive, and a -1 if it is negative. It returns 0 if the value is 0. Simple. The GDScript documentation had the examples I was looking for as well.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.