Sgn: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "SGN(''number'') '''Description''' SGN returns an integer indicating the sign of a number. The required parameter, number, is any valid numeric expression. If number is less ..."
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
SGN(''number'')
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.''  


'''Description'''
Sgn(''number'')


SGN returns an integer indicating the sign of a number. The required parameter, number, is any valid numeric expression. If number is less than zero -1 is returned, if number is greater than zero 1 is returned, if number is equal to zero, 0 is returned.
== Description ==


'''Example'''
Sgn returns an integer indicating the sign of a number. The required parameter, ''number'', is any valid numeric expression. If ''number'' is less than zero -1 is returned, if ''number'' is greater than zero 1 is returned, if ''number'' is equal to zero, 0 is returned.
 
== Example (BASIC) ==


<pre>
<pre>
REM SGN Example
Rem Sgn Example
'SGN returns the sign of a number as -1 or 1
'Sgn returns the sign of a number as -1 or 1
DIM Pos, Neg, Zero
Dim Pos, Neg, Zero
Pos = SGN(44)
Pos = Sgn(44)
Neg = SGN(-17)
Neg = Sgn(-17)
Zero = SGN(100 - 100)
Zero = Sgn(100 - 100)
PRINT "Positive:", Pos
Print "Positive:", Pos
PRINT "Negative:", Neg
Print "Negative:", Neg
PRINT "Zero:", Zero
Print "Zero:", Zero
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 27: Line 29:
</pre>
</pre>


'''Related Items'''
== Related Items ==
 
[[abs|Abs]]
 
[[Category:Language Reference]]
 
[[Category:Math]]


[[abs|ABS]]
[[Category:BASIC Functions]]

Latest revision as of 15:34, 25 March 2019

This function is for BASIC compatibility. It is not available in pure JavaScript projects.

Sgn(number)

Description

Sgn returns an integer indicating the sign of a number. The required parameter, number, is any valid numeric expression. If number is less than zero -1 is returned, if number is greater than zero 1 is returned, if number is equal to zero, 0 is returned.

Example (BASIC)

Rem Sgn Example
'Sgn returns the sign of a number as -1 or 1
Dim Pos, Neg, Zero
Pos = Sgn(44)
Neg = Sgn(-17)
Zero = Sgn(100 - 100)
Print "Positive:", Pos
Print "Negative:", Neg
Print "Zero:", Zero

Output

Positive:     1
Negative:     -1
Zero:  0

Related Items

Abs