julia example
Julia| sign()函数 (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.
sign()函数是Julia编程语言中的库函数,它以-1 / + 1的形式返回给定值的符号。
Note: If the value is 0, it returns 0.
注意:如果该值为0,则返回0。
Syntax:
句法:
sign(val)
Parameter(s):
参数:
val – represents a signed integer/value, whose sign (-1 or +1) to be found.
val –表示一个有符号的整数/值,其符号(-1或+1)将被找到。
Return value:
返回值:
The return type of this method is Int64, it returns the -1 or +1 for the val.
此方法的返回类型为Int64 ,它返回val的-1或+1。
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
翻译自: https://www.includehelp.com/julia/sign-function-with-example.aspx
julia example