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 10println( "abs(10) => $(abs(10))")## find abs of -3println( "abs(-3) => $(abs(-3))")## find abs of -3.6println( "abs(-3.6) => $(abs(-3.6))")
Explanation
- Line 2: We use the
absmethod with10as an argument. Theabs(10)will return10.
- Line 5: We use the
absmethod with-3as an argument. Theabs(-3)will return3.
- Line 8: We use the
absmethod with3.6as an argument. Theabs(-3.6)will return3.6.