User Tools

Site Tools


ugbasic:user:kw:sgn
Translations of this page:


ugBASIC User Manual

SGN ✓

SYNTAX

   = SGN(number)

PURPOSE

The SGN function is a very simple but useful mathematical function. Its main function is to determine the sign of a number. In other words, SGN tells you whether a number is positive, negative, or zero. So, it returns 1 if number is positive, 0 if number is zero and -1 if number is negative.

You can use SGN inside an IF condition to perform different actions depending on the sign of a number, and in some cases, SGN can make your code more concise and readable.

EXAMPLE

  x = SNG(-42)

See also the following example files:

ABBREVIATION

 Sg

AVAILABLE ON

ANY PROBLEM?

If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!

POWERED BY