在 Julia 中获取数字的绝对值 – abs() 方法
abs()
是 julia 中的内置函数,用于返回指定数字x的绝对值。
Syntax: abs(x)
Parameters:
- x: Specified value.
Returns: It returns the absolute value of the specified number x.
示例 1:
# Julia program to illustrate
# the use of abs() method
# Getting absolute value of the
# specified number x
println(abs(0))
println(abs(-2.7))
println(abs(2))
输出:
0
2.7
2
示例 2:
# Julia program to illustrate
# the use of abs() method
# Getting absolute value of the
# specified number x
println(abs(0))
println(abs(-2.7))
println(abs(-2.9))
println(abs(0.7))
println(abs(-0.2))
println(abs(-22))
输出:
0
2.7
2.9
0.7
0.2
22