Getting square root of a number in Julia – sqrt() and isqrt() Methods
Last Updated :
26 Mar, 2020
The
sqrt()
is an inbuilt function in
julia which is used to return the square root of the specified number and throws DomainError for negative Real parameter. It also accept complex negative parameter.
Syntax: sqrt(x)
Parameters:
Returns: It returns the square root of the specified number and throws DomainError for negative Real parameter. It also accept complex negative parameter.
Example:
println(sqrt( 9 ))
println(sqrt( 16 ))
println(sqrt( complex ( - 25 )))
println(sqrt( - 49 ))
|
Output:
3.0
4.0
0.0 + 5.0im
ERROR: LoadError: DomainError:
sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)).
Stacktrace:
[1] sqrt(::Int64) at ./math.jl:434
while loading /home/cg/root/9093667/main.jl, in expression starting on line 10
isqrt()
The
isqrt()
is an inbuilt function in
julia which is used to return integer square root of the specified value. The largest returned integer value m(say) such that
Syntax:
isqrt(n::Integer)
Parameters:
- n::Integer: Specified values.
Returns: It returns integer square root of the specified value.
Example:
println(isqrt( 12 ))
println(isqrt( 17 ))
println(isqrt( 5 ))
println(isqrt( 227 ))
|
Output:
3
4
2
15
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...