在 Julia 中获取乘法恒等式 – one() 方法
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))
输出: