From c25ee9f13f7ffe5ff0e0d96395294ef173a6ece3 Mon Sep 17 00:00:00 2001 From: stomar Date: Sun, 26 Feb 2017 12:51:41 +0000 Subject: [PATCH] Add rdoc for Integer.sqrt * numeric.c (rb_int_s_isqrt): [DOC] add rdoc for Integer.sqrt. [ruby-core:79762] [Bug #13251] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/numeric.c b/numeric.c index b34fb0a5f9..064b6c8509 100644 --- a/numeric.c +++ b/numeric.c @@ -5154,6 +5154,32 @@ DEFINE_INT_SQRT(BDIGIT, rb_bdigit_dbl, BDIGIT_DBL) VALUE rb_big_isqrt(VALUE); +/* + * Document-method: Integer::sqrt + * call-seq: + * Integer.sqrt(n) -> integer + * + * 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. + */ + static VALUE rb_int_s_isqrt(VALUE self, VALUE num) {