one()
是 julia 中的一个内置函数,用于返回指定值 x 的乘法标识,其中 x 是满足 one(x)*x == x*one(x) == x 的值。
Syntax:
one(x)
or
one(T::type)
Parameters:
- : Specified value.
- one(T::type): Specified number type.
Returns: It returns a multiplicative identity of the specified value x, where x is a value such that one(x)*x == x*one(x) == x.
示例 1:
# Julia program to illustrate
# the use of one() method
# Getting return a multiplicative
# identity of the specified value x
println(one(0))
println(one(1))
println(one(5))
println(one(5.9))
输出:
1
1
1
1.0
示例 2:
# Julia program to illustrate
# the use of one() method
# Getting return a multiplicative
# identity of the specified number type
println(one(Int))
println(one(String))
输出: