Open In App

Getting additive identity element in Julia – zero() Method

The zero() is an inbuilt function in julia which is used to return the additive identity element for the type of x, where x might also be type itself.

Syntax: zero(x)



Parameters:

  • x: Specified value.

Returns: It returns the additive identity element for the type of x, where x might also be type itself.



Example 1:




# Julia program to illustrate 
# the use of zero() method
   
# Getting the additive identity element
# for the type of given parameter
println(zero(0))
println(zero(1))
println(zero(5.6))
println(zero(big"2.0"))

Output:

Example 2:




# Julia program to illustrate 
# the use of zero() method
   
# Getting the additive identity element
# for the type of given parameter
println(zero(rand(1, 1)))
println(zero(rand(2, 2)))
println(zero(rand(3, 3)))

Output:

[0.0]
[0.0 0.0; 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
Article Tags :