method
sqrt
v2_6_3 -
Show latest stable
-
0 notes -
Class: Integer
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
sqrt(p1)
public
Returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n.
Integer.sqrt(0) #=> 0 Integer.sqrt(1) #=> 1 Integer.sqrt(24) #=> 4 Integer.sqrt(25) #=> 5 Integer.sqrt(10**400) #=> 10**200
Equivalent to Math.sqrt(n).floor, except that the result of the latter code may differ from the true value due to the limited precision of floating point arithmetic.
Integer.sqrt(10**46) #=> 100000000000000000000000 Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
If n is not an Integer, it is converted to an Integer first. If n is negative, a Math::DomainError is raised.