Open In App

Getting multiplicative identity in Julia – one() Method

Last Updated : 01 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The one() is an inbuilt function in julia which is used to return a multiplicative identity of the specified value x, where x is a value such that 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.

Example 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))


Output:

1
1
1
1.0

Example 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))


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads