Doc: Abs( )

( PlayBasic 1.61 )

Abs - return the absolute value of a number.

Syntax

num = Abs ( x )

  • num - returned absolute value
  • x - number to get the absolute value of

Explanation

Abs() returns the absolute value of a number. The absolute value of a number is it's distance from zero. 5 and -5 are both 5 "units" away from 0, therefore, Abs() will return 5 in both cases.

Examples

Get the Absolute Value of a Number

In the example code below, both numbers are printed as positive 42.

Print Abs(42)
Print Abs(-42)
Sync
WaitKey

Related Pages

Math Functions

  • GetSign() - check if a number is negative
  • Neg() - reverse the sign of a number

Source Code

User Functions

  • MakeNeg() - make a number negative

Links

Categories: Functions : Math