sqrt()
是 julia 中的一个内置函数,用于返回指定数字的平方根,并为负 Real 参数抛出 DomainError。它还接受复杂的负参数。
Syntax: sqrt(x)
Parameters:
- x: Specified values.
Returns: It returns the square root of the specified number and throws DomainError for negative Real parameter. It also accept complex negative parameter.
例子:
# Julia program to illustrate
# the use of sqrt() method
# Getting the square root of the
# specified number and throws DomainError
# for negative Real parameter
println(sqrt(9))
println(sqrt(16))
println(sqrt(complex(-25)))
println(sqrt(-49))
输出:
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()
isqrt()
是 julia 中的一个内置函数,用于返回指定值的整数平方根。最大的返回整数值 m(say) 使得
Syntax:
isqrt(n::Integer)
Parameters:
- n::Integer: Specified values.
Returns: It returns integer square root of the specified value.
例子:
# Julia program to illustrate
# the use of isqrt() method
# Getting integer square root of the specified value.
println(isqrt(12))
println(isqrt(17))
println(isqrt(5))
println(isqrt(227))
输出:
3
4
2
15