aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authorstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-26 12:51:41 +0000
committerstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-26 12:51:41 +0000
commit9e8ee1b0a81eeb0966a416498ade42ea1f6ebdac (patch)
tree179ad009444b803268a1205c1c68240b1c0d4313 /numeric.c
parentc6b75f1cc691c91cdbbd8f4e8bb5c1571704a8ee (diff)
downloadruby-9e8ee1b0a81eeb0966a416498ade42ea1f6ebdac.tar.gz
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
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c26
1 files changed, 26 insertions, 0 deletions
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 <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)
{