How to use the abs() method in Julia

Overview

The abs(x) method will return the absolute value of x. The absolute value denotes the non-negative value of x without regard to its sign.

Syntax

abs(x)
Julia abs function Syntax

Parameters

x: The value for which the absolute value is to be found.

Return value

The absolute value of the specified value will be returned.

Code

The code below demonstrates how to use the abs method.

## find abs of 10
println( "abs(10) => $(abs(10))")
## find abs of -3
println( "abs(-3) => $(abs(-3))")
## find abs of -3.6
println( "abs(-3.6) => $(abs(-3.6))")

Explanation

  • Line 2: We use the abs method with 10 as an argument. The abs(10) will return 10.
  • Line 5: We use the abs method with -3 as an argument. The abs(-3)will return 3.
  • Line 8: We use the abs method with 3.6 as an argument. The abs(-3.6) will return 3.6.

Free Resources