Home » Julia

abs() Function with Example in Julia

Julia | abs() function: In this tutorial, we are going to learn about the abs() function with example in the Julia programming language.
Submitted by IncludeHelp, on April 04, 2020

Julia | abs() function

abs() function is a library function in Julia programming language, it is used to get the absolute value of the given signed integer.

Note: There an overflow occurs when the function is applied to the minimum value of a data type.

Syntax:

    abs(val)

Parameter(s):

  • val – represents a signed integer/value, whose absolute value to be found.

Return value:

The return type of this method is Int64, it returns the absolute value of val.

Example:

    Input:
    val = 0
    Output:
    abs(val): 0

    Input:
    val = -10
    Output:
    abs(val): 10

    Input:
    val = 10
    abs(val): 10

Program:

# abs() Function with Example in Julia

val = 0
println("val: ", val)
println("abs(val): ", abs(val))

val = 10
println("val: ", val)
println("abs(val): ", abs(val))

val = -10
println("val: ", val)
println("abs(val): ", abs(val))

val = 10.23
println("val: ", val)
println("abs(val): ", abs(val))

val = -10.23
println("val: ", val)
println("abs(val): ", abs(val))

# special case
println("typemin(Int64): ", typemin(Int64))
println("abs(typemin(Int64)): ", abs(typemin(Int64)))

# printing the return type of abs()
println("typeof(abs(-10)): ", typeof(abs(-10)))

Output

val: 0
abs(val): 0
val: 10
abs(val): 10
val: -10
abs(val): 10
val: 10.23
abs(val): 10.23
val: -10.23
abs(val): 10.23
typemin(Int64): -9223372036854775808
abs(typemin(Int64)): -9223372036854775808
typeof(abs(-10)): Int64


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.