ABS()

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

This function returns the absolute value of the given number or expression.
For negative values it will return the positive value.

Syntax

  1. ABS(Number)

Hints

Most mathematical operations in BASIC can be performed on Literal Numbers, Numeric Variables or Numeric Expressions that consist of Literal Numbers, Numeric Variables or both.

Example

Print ABS(2)
Print ABS(3.5)
Print ABS(-0.2)
Print ABS(2*1.5)
End

Produces: 2 3.5 0.2 3.0

Useful Procedures

Function SGN(number)
    ' This function returns the sign of a number:
    '    -1 ... negative number
    '     0 ... zero
    '     1 ... positive number

    If number <> 0 Then SGN = number / ABS(number)
End Function