mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
1a155ee7f6
commit
2e35696bbe
1 changed files with 43 additions and 1 deletions
44
math.c
44
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]
|
||||
|
|
Loading…
Reference in a new issue