isqrt
isqrt(n)
Integer square root: the largest integer m
such that m*m <= n
.
Examples
-
Calculate the integer square root of a number:
julia> isqrt(25) 5 julia> isqrt(37) 6
This example calculates the integer square root of the given numbers
25
and37
, returning the largest integerm
such thatm * m <= n
. -
Handle perfect square numbers:
julia> isqrt(16) 4 julia> isqrt(100) 10
When the input number is a perfect square, the integer square root is the exact square root value.
- Calculate the integer square root of large numbers:
julia> isqrt(10000000000000000000000000000000000000000000000000000000000000000000) 316227766016837933199889354443271853371955513932521682685750485607663030888
The
isqrt
function can handle large numbers and still provide accurate results.
Common mistake example:
julia> isqrt(3.14)
ERROR: MethodError: no method matching isqrt(::Float64)
In this example, the isqrt
function is called with a floating-point number. However, isqrt
only works on integers, so passing a float will result in a MethodError
. Make sure to provide an integer as the argument to isqrt
.
See Also
digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.