Futurebasic/Language/Reference/sgn

From Wikibooks, open books for an open world
Jump to navigation Jump to search

SGN[edit | edit source]

Syntax[edit | edit source]

signOfExpr = SGN(expr)

Description[edit | edit source]

Use this function to determine the "sign" of expr. SGN returns:

  • 1 if expr is positive;
  • 0 if expr is zero;
  • -1 if expr is negative.

Example[edit | edit source]

This loop counts up if first, and counts down if last:

<code><b>FOR</b> x = first <b>TO</b> last <b>STEP</b> <b>SGN</b>(last-first)<br>
<b>   PRINT</b> x<br>
<b>NEXT</b></code>

See Also[edit | edit source]

FOR; ABS