From 2e35696bbec28b0f0252292191ba38d8164da3a2 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 15 Jun 2008 02:13:16 +0000 Subject: [PATCH] add an example to rdoc of sqrt and cbrt. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- math.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/math.c b/math.c index 6bf233acee..d3577f983f 100644 --- a/math.c +++ b/math.c @@ -399,6 +399,23 @@ math_log10(VALUE obj, VALUE x) * Math.sqrt(numeric) => float * * Returns the non-negative square root of numeric. + * + * 0.upto(10) {|x| + * p [x, Math.sqrt(x), Math.sqrt(x)**2] + * } + * #=> + * [0, 0.0, 0.0] + * [1, 1.0, 1.0] + * [2, 1.4142135623731, 2.0] + * [3, 1.73205080756888, 3.0] + * [4, 2.0, 4.0] + * [5, 2.23606797749979, 5.0] + * [6, 2.44948974278318, 6.0] + * [7, 2.64575131106459, 7.0] + * [8, 2.82842712474619, 8.0] + * [9, 3.0, 9.0] + * [10, 3.16227766016838, 10.0] + * */ VALUE @@ -418,6 +435,31 @@ math_sqrt(VALUE obj, VALUE x) * Math.cbrt(numeric) => float * * Returns the cube root of numeric. + * + * -9.upto(9) {|x| + * p [x, Math.cbrt(x), Math.cbrt(x)**3] + * } + * #=> + * [-9, -2.0800838230519, -9.0] + * [-8, -2.0, -8.0] + * [-7, -1.91293118277239, -7.0] + * [-6, -1.81712059283214, -6.0] + * [-5, -1.7099759466767, -5.0] + * [-4, -1.5874010519682, -4.0] + * [-3, -1.44224957030741, -3.0] + * [-2, -1.25992104989487, -2.0] + * [-1, -1.0, -1.0] + * [0, 0.0, 0.0] + * [1, 1.0, 1.0] + * [2, 1.25992104989487, 2.0] + * [3, 1.44224957030741, 3.0] + * [4, 1.5874010519682, 4.0] + * [5, 1.7099759466767, 5.0] + * [6, 1.81712059283214, 6.0] + * [7, 1.91293118277239, 7.0] + * [8, 2.0, 8.0] + * [9, 2.0800838230519, 9.0] + * */ static VALUE @@ -524,7 +566,7 @@ math_erfc(VALUE obj, VALUE x) * * def fact(n) (1..n).inject(1) {|r,i| r*i } end * 0.upto(25) {|i| p [i, Math.gamma(i+1), fact(i)] } - * => + * #=> * [0, 1.0, 1] * [1, 1.0, 1] * [2, 2.0, 2]