Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

ABS

Keyword Abbreviation Token (hex) Version(s) Classification
ABS A{Shift+B} B6 1.0+ Function

  Syntax  
ABS value )
 
Parameters Type Legal Value(s) Default Value Note(s)
value Numeric
any
 
Returns Type Value(s) Note(s)
result Floating-point
any non-negative
 
  Purpose  
Calculate the absolute value of a number.

 
  Remarks  
The ABS function simply returns the value with sign "changed" to positive.  Of course if the original value was not negative, the result is the same as the original value.  This function would be more useful if CBM BASIC supported complex numbers.  But even limited to real numbers, it comes in handy, and is MUCH faster than calculating SQR(value*value).  Use it when you want to ensure a number is positive (as required by some functions).  Also useful for working with polar coordinates or implementing complex numbers.
 
You will get TYPE MISMATCH ERROR with a string value.  If value is missing or not a valid expression, SYNTAX ERROR is generated.
  
Examples:
PRINT ABS(2)
 2
 
READY.
PRINT ABS(-2)
 2

READY.
PRINT -XOR(ABS(A<0), ABS(A>B))
 0

READY.
 
  Compare With  
+, -
 
  Contrast With  
 
  See Also  
ATN, SQR 

© H2Obsession, 2014
Comments