summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 02:13:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 02:13:16 +0000
commit2e35696bbec28b0f0252292191ba38d8164da3a2 (patch)
tree85b5c828cf6e511504c1afcf1ffee4cb7a48f4ad /math.c
parent1a155ee7f697f8dd791bda46afc2be2ebe806207 (diff)
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
Diffstat (limited to 'math.c')
-rw-r--r--math.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/math.c b/math.c
index 6bf233a..d3577f9 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 <i>numeric</i>.
+ *
+ * 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 <i>numeric</i>.
+ *
+ * -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]