Difference between revisions of "SGN"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m (format)
imported>Keybone
m (Added missing comma, fixed wording of function description to make less ambiguous.)
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
  
::::''Syntax:'' sign% = SGN(value)
+
{{PageSyntax}}
 +
:: sign% = SGN(value)
  
  
  
* Returns -1 when a sign is negative, 0 when a value is zero or 1 when a value is positive.
+
* Returns -1 when a sign is negative, 0 when a value is zero, or 1 when a value is positive.
* Used to hold the original sign of a number.
+
* Function is used to store the original sign of a number.
 
* '''QB64''' allows programs to return only [[_UNSIGNED]] variable values using a [[_DEFINE]] statement.
 
* '''QB64''' allows programs to return only [[_UNSIGNED]] variable values using a [[_DEFINE]] statement.
  
Line 15: Line 16:
 
''Example:'' Checking and changing negative values to positive ones.
 
''Example:'' Checking and changing negative values to positive ones.
 
{{CodeStart}}
 
{{CodeStart}}
 
 
n = -100
 
n = -100
IF SGN(n) = -1 THEN n = [[ABS]](n)
+
{{Cl|IF...THEN|IF}} {{Cl|SGN}}(n) = -1 THEN n = {{Cl|ABS}}(n)
PRINT n
+
PRINT n '' ''
 
 
 
{{CodeEnd}}
 
{{CodeEnd}}
{{OutputStart}}
+
{{OutputStart}} 100
100
 
 
{{OutputEnd}}
 
{{OutputEnd}}
  
  
 
''See also:''  
 
''See also:''  
 
 
* [[ABS]]
 
* [[ABS]]
 
* [[_DEFINE]], [[_UNSIGNED]]  
 
* [[_DEFINE]], [[_UNSIGNED]]  
 
* [[Mathematical Operations]]
 
* [[Mathematical Operations]]
 
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Latest revision as of 02:36, 30 July 2019

The SGN function returns the sign of a number value.


Syntax

sign% = SGN(value)


  • Returns -1 when a sign is negative, 0 when a value is zero, or 1 when a value is positive.
  • Function is used to store the original sign of a number.
  • QB64 allows programs to return only _UNSIGNED variable values using a _DEFINE statement.


Example: Checking and changing negative values to positive ones.

n = -100 IF SGN(n) = -1 THEN n = ABS(n) PRINT n

100


See also:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page