Retro Rocket OS
BASIC-Powered Operating System
Loading...
Searching...
No Matches
SGN Function
SGN(integer-expression)

Returns the sign of an integer expression:

  • -1 if the expression is negative
  • 0 if the expression is zero
  • 1 if the expression is positive

Examples

PRINT SGN(-42)

Produces -1.

PRINT SGN(0)

Produces 0.

PRINT SGN(1234)

Produces 1.

REM Use SGN in a comparison
balance = -150
IF SGN(balance) = -1 THEN
PRINT "Account overdrawn!"
ENDIF

Notes

  • Input must be an integer expression.
  • Return value is always -1, 0, or 1.
  • Can be used in compact conditionals or arithmetic to simplify sign handling.

See also: ABS · INT · ROUND