Attention |
Topic was automatically imported from the old Question2Answer platform. | |

Asked By |
Sylkie |

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?

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

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

Ertain | 2019-10-27 18:23

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

Sylkie | 2019-10-27 18:41

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.

Ertain | 2019-10-28 00:10

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.

Sylkie | 2019-10-28 02:56