SGN function

Purpose

Return the sign of a numeric expression.

Syntax

y = SGN(numeric_expression)

Remarks

If numeric_expression is positive, SGN returns 1.  If numeric_expression is zero, SGN returns 0.  If numeric_expression is negative, SGN returns -1.

In conjunction with the ON GOTO and ON GOSUB statements, SGN can produce a FORTRAN-like three-way branch:

ON SGN(balance) + 2 GOTO InTheRed, BreakingEven, InTheMoney

See also

ABS, IF, ON GOSUB, ON GOTO, SELECT

Example

' ON SGN value, GOSUB appropriate subroutine

ON SGN (value) + 2 GOSUB Minus, Zero, Plus

...

Minus:

x$ = "The product is negative" : RETURN

Zero:

x$ = "The product is zero"     : RETURN

Plus:

x$ = "The product is positive" : RETURN