[前][次][番号順一覧][スレッド一覧]

ruby-changes:5656

From: akr <ko1@a...>
Date: Sun, 15 Jun 2008 11:16:48 +0900 (JST)
Subject: [ruby-changes:5656] Ruby:r17163 (trunk): add an example to rdoc of sqrt and cbrt.

akr	2008-06-15 11:13:16 +0900 (Sun, 15 Jun 2008)

  New Revision: 17163

  Modified files:
    trunk/math.c

  Log:
    add an example to rdoc of sqrt and cbrt.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/math.c?r1=17163&r2=17162&diff_format=u

Index: math.c
===================================================================
--- math.c	(revision 17162)
+++ math.c	(revision 17163)
@@ -399,6 +399,23 @@
  *     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.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 @@
  *
  *   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]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]