How to use the abs2() method in Julia

         

Overview

The abs2(x) method returns the square of the absolute valueAbsolute value denotes the non-negative value of x without regard to its sign. of a given x.

Syntax

abs2(x)
Julia abs() function Syntax

Argument

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

Return value

The square of absolute value for the specified value will be returned.

Code

The code below demonstrates how to use the abs() method.

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

Explanation

In the code above, we do the following:

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

Free Resources