ABS: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
Tags: Undo Reverted
No edit summary
Tags: Manual revert Reverted
Line 8: Line 8:
{{PageDescription}}
{{PageDescription}}
* [[ABS]] always returns positive numerical values. The value can be any numerical type.
* [[ABS]] always returns positive numerical values. The value can be any numerical type.
* Often used to keep a value positive when necessary in a program.  
* Often used to keep a value positive when necessary in a program.
* Use [[SGN]] to determine a value's sign when necessary.
* Use [[SGN]] to determine a value's sign when necessary.
* '''QB64''' allows programs to return only positive [[_UNSIGNED]] variable values using a [[DIM]] or [[_DEFINE]] statement.
* '''QB64''' allows programs to return only positive [[_UNSIGNED]] variable values using a [[DIM]] or [[_DEFINE]] statement.
Line 22: Line 22:
b = {{Cl|ABS}}(b)
b = {{Cl|ABS}}(b)
c = {{Cl|ABS}}(c)
c = {{Cl|ABS}}(c)
{{Cl|PRINT}} a, b, c  
{{Cl|PRINT}} a, b, c
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}} 6        7        8
{{OutputStart}} 6        7        8

Revision as of 22:58, 22 January 2023

The ABS function returns the unsigned numerical value of a variable or literal value.


Syntax

positive = ABS(numericalValue)


Description

  • ABS always returns positive numerical values. The value can be any numerical type.
  • Often used to keep a value positive when necessary in a program.
  • Use SGN to determine a value's sign when necessary.
  • QB64 allows programs to return only positive _UNSIGNED variable values using a DIM or _DEFINE statement.


Examples

Example: Finding the absolute value of positive and negative numerical values.

a = -6
b = -7
c = 8
IF a < 0 THEN a = ABS(a)
b = ABS(b)
c = ABS(c)
PRINT a, b, c
 6        7        8


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link