Skip to content

SGN

Syntax

SGN(X)

Versions: 8K, Extended, Disk

Description

Returns the sign of a number. If X>0, SGN(X) returns 1. If X=0, SGN(X) returns 0. If X<0, SGN(X) returns -1.

Example

ON SGN(X) + 2 GOTO 100, 200, 300

This branches to: - Line 100 if X is negative (SGN returns -1, so -1+2=1, first GOTO target) - Line 200 if X is 0 (SGN returns 0, so 0+2=2, second GOTO target) - Line 300 if X is positive (SGN returns 1, so 1+2=3, third GOTO target)

See Also

  • ABS - Return the absolute value of a number (removes negative sign)
  • ATN - Returns the arctangent of X in radians
  • COS - Returns the cosine of X in radians
  • EXP - Returns e to the power of X
  • FIX - Returns the truncated integer part of X
  • INT - Return the largest integer less than or equal to a number (floor function)
  • LOG - Returns the natural logarithm of X
  • RND - Returns a random number between 0 and 1
  • SIN - Returns the sine of X in radians
  • SQR - Returns the square root of X
  • TAN - Returns the tangent of X in radians