summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-26 12:51:41 (GMT)
committerstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-26 12:51:41 (GMT)
commitc25ee9f13f7ffe5ff0e0d96395294ef173a6ece3 (patch)
tree179ad009444b803268a1205c1c68240b1c0d4313 /numeric.c
parent5c5d8944749a47920e469b758df838de1c6c6745 (diff)
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 b34fb0a..064b6c8 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)
{