ruby-changes:45646
From: stomar <ko1@a...>
Date: Sun, 26 Feb 2017 21:51:48 +0900 (JST)
Subject: [ruby-changes:45646] stomar:r57719 (trunk): Add rdoc for Integer.sqrt
stomar 2017-02-26 21:51:41 +0900 (Sun, 26 Feb 2017) New Revision: 57719 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57719 Log: Add rdoc for Integer.sqrt * numeric.c (rb_int_s_isqrt): [DOC] add rdoc for Integer.sqrt. [ruby-core:79762] [Bug #13251] Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 57718) +++ numeric.c (revision 57719) @@ -5154,6 +5154,32 @@ DEFINE_INT_SQRT(BDIGIT, rb_bdigit_dbl, B https://github.com/ruby/ruby/blob/trunk/numeric.c#L5154 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 <code>Math.sqrt(n).floor</code>, 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) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/