Home »
Julia
sign() Function with Example in Julia
Julia | sign() function: In this tutorial, we are going to learn about the sign() function with example in the Julia programming language.
Submitted by IncludeHelp, on April 04, 2020
Julia | sign() function
sign() function is a library function in Julia programming language, it returns the sign of the given value in the form of -1/+1.
Note: If the value is 0, it returns 0.
Syntax:
sign(val)
Parameter(s):
- val – represents a signed integer/value, whose sign (-1 or +1) to be found.
Return value:
The return type of this method is Int64, it returns the -1 or +1 for the val.
Example:
Input:
val = 0
Output:
sign(val): 0
Input:
val = -10
Output:
sign(val): -1
Input:
val = 10
sign(val): +1
Program:
# sign() Function with Example in Julia
val = 0
println("val: ", val)
println("sign(val): ", sign(val))
val = 10
println("val: ", val)
println("sign(val): ", sign(val))
val = -10
println("val: ", val)
println("sign(val): ", sign(val))
val = 10.23
println("val: ", val)
println("sign(val): ", sign(val))
val = -10.23
println("val: ", val)
println("sign(val): ", sign(val))
# printing the return type of sign()
println("typeof(sign(-10)): ", typeof(sign(-10)))
Output
val: 0
sign(val): 0
val: 10
sign(val): 1
val: -10
sign(val): -1
val: 10.23
sign(val): 1.0
val: -10.23
sign(val): -1.0
typeof(sign(-10)): Int64