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

ruby-changes:25403

From: tadf <ko1@a...>
Date: Sat, 3 Nov 2012 23:40:00 +0900 (JST)
Subject: [ruby-changes:25403] tadf:r37460 (trunk): * complex.c: modified doc.

tadf	2012-11-03 23:39:50 +0900 (Sat, 03 Nov 2012)

  New Revision: 37460

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37460

  Log:
    * complex.c: modified doc.
    * rational.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c

Index: complex.c
===================================================================
--- complex.c	(revision 37459)
+++ complex.c	(revision 37460)
@@ -440,8 +440,7 @@
  *
  * Returns a complex object which denotes the given rectangular form.
  *
- * For example:
- *   Complex.rect(12, 2) # => (12+2i)
+ *    Complex.rectangular(1, 2)  #=> (1+2i)
  */
 static VALUE
 nucomp_s_new(int argc, VALUE *argv, VALUE klass)
@@ -481,6 +480,8 @@
  *    Complex(x[, y])  ->  numeric
  *
  * Returns x+i*y;
+ *
+ *    Complex(1, 2)  #=> (1+2i)
  */
 static VALUE
 nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
@@ -590,10 +591,10 @@
  *
  * Returns a complex object which denotes the given polar form.
  *
- *   Complex.polar(3, 0)           #=> (3.0+0.0i)
- *   Complex.polar(3, Math::PI/2)  #=> (1.836909530733566e-16+3.0i)
- *   Complex.polar(3, Math::PI)    #=> (-3.0+3.673819061467132e-16i)
- *   Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)
+ *    Complex.polar(3, 0)            #=> (3.0+0.0i)
+ *    Complex.polar(3, Math::PI/2)   #=> (1.836909530733566e-16+3.0i)
+ *    Complex.polar(3, Math::PI)     #=> (-3.0+3.673819061467132e-16i)
+ *    Complex.polar(3, -Math::PI/2)  #=> (1.836909530733566e-16-3.0i)
  */
 static VALUE
 nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
@@ -618,6 +619,9 @@
  *    cmp.real  ->  real
  *
  * Returns the real part.
+ *
+ *    Complex(7).real      #=> 7
+ *    Complex(9, -4).real  #=> 9
  */
 static VALUE
 nucomp_real(VALUE self)
@@ -632,6 +636,9 @@
  *    cmp.imaginary  ->  real
  *
  * Returns the imaginary part.
+ *
+ *    Complex(7).imaginary      #=> 0
+ *    Complex(9, -4).imaginary  #=> -4
  */
 static VALUE
 nucomp_imag(VALUE self)
@@ -645,6 +652,8 @@
  *    -cmp  ->  complex
  *
  * Returns negation of the value.
+ *
+ *    -Complex(1, 2)  #=> (-1-2i)
  */
 static VALUE
 nucomp_negate(VALUE self)
@@ -683,10 +692,11 @@
  *
  * Performs addition.
  *
- *   Complex(5, 2) + 3 # => (8+2i)
- *   Complex(5, 2) + 3.i # => (5+5i)
- *   Complex(5, 2) + Complex(3, 4) # => (8+6i)
- *
+ *    Complex(2, 3)  + Complex(2, 3)   #=> (4+6i)
+ *    Complex(900)   + Complex(1)      #=> (901+0i)
+ *    Complex(-2, 9) + Complex(-9, 2)  #=> (-11+11i)
+ *    Complex(9, 8)  + 4               #=> (13+8i)
+ *    Complex(20, 9) + 9.8             #=> (29.8+9i)
  */
 static VALUE
 nucomp_add(VALUE self, VALUE other)
@@ -700,7 +710,11 @@
  *
  * Performs subtraction.
  *
- *   Complex(33, 12) - 10 # => (23+12i)
+ *    Complex(2, 3)  - Complex(2, 3)   #=> (0+0i)
+ *    Complex(900)   - Complex(1)      #=> (899+0i)
+ *    Complex(-2, 9) - Complex(-9, 2)  #=> (7+7i)
+ *    Complex(9, 8)  - 4               #=> (5+8i)
+ *    Complex(20, 9) - 9.8             #=> (10.2+9i)
  */
 static VALUE
 nucomp_sub(VALUE self, VALUE other)
@@ -714,7 +728,11 @@
  *
  * Performs multiplication.
  *
- *   Complex(78, 58) * 10 # => (780+580i)
+ *    Complex(2, 3)  * Complex(2, 3)   #=> (-5+12i)
+ *    Complex(900)   * Complex(1)      #=> (900+0i)
+ *    Complex(-2, 9) * Complex(-9, 2)  #=> (0-85i)
+ *    Complex(9, 8)  * 4               #=> (36+32i)
+ *    Complex(20, 9) * 9.8             #=> (196.0+88.2i)
  */
 static VALUE
 nucomp_mul(VALUE self, VALUE other)
@@ -802,10 +820,11 @@
  *
  * Performs division.
  *
- * For example:
- *
- *     Complex(10.0) / 3  #=> (3.3333333333333335+(0/1)*i)
- *     Complex(10)   / 3  #=> ((10/3)+(0/1)*i)  # not (3+0i)
+ *    Complex(2, 3)  / Complex(2, 3)   #=> ((1/1)+(0/1)*i)
+ *    Complex(900)   / Complex(1)      #=> ((900/1)+(0/1)*i)
+ *    Complex(-2, 9) / Complex(-9, 2)  #=> ((36/85)-(77/85)*i)
+ *    Complex(9, 8)  / 4               #=> ((9/4)+(2/1)*i)
+ *    Complex(20, 9) / 9.8             #=> (2.0408163265306123+0.9183673469387754i)
  */
 static VALUE
 nucomp_div(VALUE self, VALUE other)
@@ -821,9 +840,7 @@
  *
  * Performs division as each part is a float, never returns a float.
  *
- * For example:
- *
- *     Complex(11,22).fdiv(3)  #=> (3.6666666666666665+7.333333333333333i)
+ *    Complex(11, 22).fdiv(3)  #=> (3.6666666666666665+7.333333333333333i)
  */
 static VALUE
 nucomp_fdiv(VALUE self, VALUE other)
@@ -843,10 +860,8 @@
  *
  * Performs exponentiation.
  *
- * For example:
- *
- *     Complex('i') ** 2             #=> (-1+0i)
- *     Complex(-8) ** Rational(1,3)  #=> (1.0000000000000002+1.7320508075688772i)
+ *    Complex('i') ** 2              #=> (-1+0i)
+ *    Complex(-8) ** Rational(1, 3)  #=> (1.0000000000000002+1.7320508075688772i)
  */
 static VALUE
 nucomp_expt(VALUE self, VALUE other)
@@ -932,6 +947,12 @@
  *    cmp == object  ->  true or false
  *
  * Returns true if cmp equals object numerically.
+ *
+ *    Complex(2, 3)  == Complex(2, 3)   #=> true
+ *    Complex(5)     == 5               #=> true
+ *    Complex(0)     == 0.0             #=> true
+ *    Complex('1/3') == 0.33            #=> false
+ *    Complex('1/2') == '1/2'           #=> false
  */
 static VALUE
 nucomp_eqeq_p(VALUE self, VALUE other)
@@ -970,6 +991,9 @@
  *    cmp.magnitude  ->  real
  *
  * Returns the absolute part of its polar form.
+ *
+ *    Complex(-1).abs         #=> 1
+ *    Complex(3.0, -4.0).abs  #=> 5.0
  */
 static VALUE
 nucomp_abs(VALUE self)
@@ -996,6 +1020,9 @@
  *    cmp.abs2  ->  real
  *
  * Returns square of the absolute value.
+ *
+ *    Complex(-1).abs2         #=> 1
+ *    Complex(3.0, -4.0).abs2  #=> 25.0
  */
 static VALUE
 nucomp_abs2(VALUE self)
@@ -1013,8 +1040,7 @@
  *
  * Returns the angle part of its polar form.
  *
- *   Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
- *
+ *    Complex.polar(3, Math::PI/2).arg  #=> 1.5707963267948966
  */
 static VALUE
 nucomp_arg(VALUE self)
@@ -1029,6 +1055,8 @@
  *    cmp.rectangular  ->  array
  *
  * Returns an array; [cmp.real, cmp.imag].
+ *
+ *    Complex(1, 2).rectangular  #=> [1, 2]
  */
 static VALUE
 nucomp_rect(VALUE self)
@@ -1042,6 +1070,8 @@
  *    cmp.polar  ->  array
  *
  * Returns an array; [cmp.abs, cmp.arg].
+ *
+ *    Complex(1, 2).polar  #=> [2.23606797749979, 1.1071487177940904]
  */
 static VALUE
 nucomp_polar(VALUE self)
@@ -1055,6 +1085,8 @@
  *    cmp.conjugate  ->  complex
  *
  * Returns the complex conjugate.
+ *
+ *    Complex(1, 2).conjugate  #=> (1-2i)
  */
 static VALUE
 nucomp_conj(VALUE self)
@@ -1122,8 +1154,6 @@
  *
  * Returns the numerator.
  *
- * For example:
- *
  *        1   2       3+4i  <-  numerator
  *        - + -i  ->  ----
  *        2   3        6    <-  denominator
@@ -1229,6 +1259,12 @@
  *    cmp.to_s  ->  string
  *
  * Returns the value as a string.
+ *
+ *    Complex(2).to_s                       #=> "2+0i"
+ *    Complex('-8/6').to_s                  #=> "-4/3+0i"
+ *    Complex('1/2i').to_s                  #=> "0+1/2i"
+ *    Complex(0, Float::INFINITY).to_s      #=> "0+Infinity*i"
+ *    Complex(Float::NAN, Float::NAN).to_s  #=> "NaN+NaN*i"
  */
 static VALUE
 nucomp_to_s(VALUE self)
@@ -1241,6 +1277,12 @@
  *    cmp.inspect  ->  string
  *
  * Returns the value as a string for inspection.
+ *
+ *    Complex(2).inspect                       #=> "(2+0i)"
+ *    Complex('-8/6').inspect                  #=> "((-4/3)+0i)"
+ *    Complex('1/2i').inspect                  #=> "(0+(1/2)*i)"
+ *    Complex(0, Float::INFINITY).inspect      #=> "(0+Infinity*i)"
+ *    Complex(Float::NAN, Float::NAN).inspect  #=> "(NaN+NaN*i)"
  */
 static VALUE
 nucomp_inspect(VALUE self)
@@ -1331,7 +1373,12 @@
  * call-seq:
  *    cmp.to_i  ->  integer
  *
- * Returns the value as an integer if possible.
+ * Returns the value as an integer if possible (the imaginary part
+ * should be exactly zero).
+ *
+ *    Complex(1, 0).to_i    #=> 1
+ *    Complex(1, 0.0).to_i  # RangeError
+ *    Complex(1, 2).to_i    # RangeError
  */
 static VALUE
 nucomp_to_i(VALUE self)
@@ -1350,7 +1397,12 @@
  * call-seq:
  *    cmp.to_f  ->  float
  *
- * Returns the value as a float if possible.
+ * Returns the value as a float if possible (the imaginary part should
+ * be exactly zero).
+ *
+ *    Complex(1, 0).to_f    #=> 1.0
+ *    Complex(1, 0.0).to_f  # RangeError
+ *    Complex(1, 2).to_f    # RangeError
  */
 static VALUE
 nucomp_to_f(VALUE self)
@@ -1369,8 +1421,12 @@
  * call-seq:
  *    cmp.to_r  ->  rational
  *
- * If the imaginary part is exactly 0, returns the real part as a Rational,
- * otherwise a RangeError is raised.
+ * Returns the value as a rational if possible (the imaginary part
+ * should be exactly zero).
+ *
+ *    Complex(1, 0).to_r    #=> (1/1)
+ *    Complex(1, 0.0).to_r  # RangeError
+ *    Complex(1, 2).to_r    # RangeError
  */
 static VALUE
 nucomp_to_r(VALUE self)
@@ -1389,8 +1445,13 @@
  * call-seq:
  *    cmp.rationalize([eps])  ->  rational
  *
- * If the imaginary part is exactly 0, returns the real part as a Rational,
- * otherwise a RangeError is raised.
+ * Returns the value as a rational if possible (the imaginary part
+ * should be exactly zero).  The optional argument eps is always
+ * ignored.
+ *
+ *    Complex(1.0/3, 0).rationalize  #=> (1/3)
+ *    Complex(1, 0.0).rationalize    # RangeError
+ *    Complex(1, 2).rationalize      # RangeError
  */
 static VALUE
 nucomp_rationalize(int argc, VALUE *argv, VALUE self)
@@ -1594,8 +1655,6 @@
  * sequences can be separated by an underscore.  Returns zero for null
  * or garbage string.
  *
- * For example:
- *
  *    '9'.to_c           #=> (9+0i)
  *    '2.5'.to_c         #=> (2.5+0i)
  *    '2.5/1'.to_c       #=> ((5/2)+0i)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37459)
+++ ChangeLog	(revision 37460)
@@ -1,3 +1,8 @@
+Sat Nov  3 23:38:15 2012  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c: modified doc.
+	* rational.c: ditto.
+
 Sat Nov  3 22:38:55 2012  Tadayoshi Funaba  <tadf@d...>
 
 	* ext/date/date_core.c: modified doc.
Index: rational.c
===================================================================
--- rational.c	(revision 37459)
+++ rational.c	(revision 37460)
@@ -548,6 +548,8 @@
  *    Rational(x[, y])  ->  numeric
  *
  * Returns x/y;
+ *
+ *    Rational(1, 2)  #=> (1/2)
  */
 static VALUE
 nurat_f_rational(int argc, VALUE *argv, VALUE klass)
@@ -561,8 +563,6 @@
  *
  * Returns the numerator.
  *
- * For example:
- *
  *    Rational(7).numerator        #=> 7
  *    Rational(7, 1).numerator     #=> 7
  *    Rational(9, -4).numerator    #=> -9
@@ -581,8 +581,6 @@
  *
  * Returns the denominator (always positive).
  *
- * For example:
- *
  *    Rational(7).denominator             #=> 1
  *    Rational(7, 1).denominator          #=> 1
  *    Rational(9, -4).denominator         #=> 4
@@ -687,8 +685,6 @@
  *
  * Performs addition.
  *
- * For example:
- *
  *    Rational(2, 3)  + Rational(2, 3)   #=> (4/3)
  *    Rational(900)   + Rational(1)      #=> (900/1)
  *    Rational(-2, 9) + Rational(-9, 2)  #=> (-85/18)
@@ -729,8 +725,6 @@
  *
  * Performs subtraction.
  *
- * For example:
- *
  *    Rational(2, 3)  - Rational(2, 3)   #=> (0/1)
  *    Rational(900)   - Rational(1)      #=> (899/1)
  *    Rational(-2, 9) - Rational(-9, 2)  #=> (77/18)
@@ -810,8 +804,6 @@
  *
  * Performs multiplication.
  *
- * For example:
- *
  *    Rational(2, 3)  * Rational(2, 3)   #=> (4/9)
  *    Rational(900)   * Rational(1)      #=> (900/1)
  *    Rational(-2, 9) * Rational(-9, 2)  #=> (1/1)
@@ -853,8 +845,6 @@
  *
  * Performs division.
  *
- * For example:
- *
  *    Rational(2, 3)  / Rational(2, 3)   #=> (1/1)
  *    Rational(900)   / Rational(1)      #=> (900/1)
  *    Rational(-2, 9) / Rational(-9, 2)  #=> (4/81)
@@ -913,8 +903,6 @@
  *
  * Performs division and returns the value as a float.
  *
- * For example:
- *
  *    Rational(2, 3).fdiv(1)       #=> 0.6666666666666666
  *    Rational(2, 3).fdiv(0.5)     #=> 1.3333333333333333
  *    Rational(2).fdiv(3)          #=> 0.6666666666666666
@@ -933,8 +921,6 @@
  *
  * Performs exponentiation.
  *
- * For example:
- *
  *    Rational(2)    ** Rational(3)    #=> (8/1)
  *    Rational(10)   ** -2             #=> (1/100)
  *    Rational(10)   ** -2.0           #=> 0.01
@@ -995,8 +981,6 @@
  *
  * Performs comparison and returns -1, 0, or +1.
  *
- * For example:
- *
  *    Rational(2, 3)  <=> Rational(2, 3)  #=> 0
  *    Rational(5)     <=> 5               #=> 0
  *    Rational(2,3)   <=> Rational(1,3)   #=> 1
@@ -1046,8 +1030,6 @@
  *
  * Returns true if rat equals object numerically.
  *
- * For example:
- *
  *    Rational(2, 3)  == Rational(2, 3)   #=> true
  *    Rational(5)     == 5                #=> true
  *    Rational(0)     == 0.0              #=> true
@@ -1172,8 +1154,6 @@
  * Equivalent to
  *    rat.truncate.
  *
- * For example:
- *
  *    Rational(2, 3).to_i   #=> 0
  *    Rational(3).to_i      #=> 3
  *    Rational(300.6).to_i  #=> 300
@@ -1246,8 +1226,6 @@
  *
  * Returns the truncated value (toward negative infinity).
  *
- * For example:
- *
  *    Rational(3).floor      #=> 3
  *    Rational(2, 3).floor   #=> 0
  *    Rational(-3, 2).floor  #=> -1
@@ -1272,8 +1250,6 @@
  *
  * Returns the truncated value (toward positive infinity).
  *
- * For example:
- *
  *    Rational(3).ceil      #=> 3
  *    Rational(2, 3).ceil   #=> 1
  *    Rational(-3, 2).ceil  #=> -1
@@ -1298,8 +1274,6 @@
  *
  * Returns the truncated value (toward zero).
  *
- * For example:
- *
  *    Rational(3).truncate      #=> 3
  *    Rational(2, 3).truncate   #=> 0
  *    Rational(-3, 2).truncate  #=> -1
@@ -1325,8 +1299,6 @@
  * Returns the truncated value (toward the nearest integer;
  * 0.5 => 1; -0.5 => -1).
  *
- * For example:
- *
  *    Rational(3).round      #=> 3
  *    Rational(2, 3).round   #=> 1
  *    Rational(-3, 2).round  #=> -2
@@ -1350,8 +1322,6 @@
  *
  * Return the value as a float.
  *
- * For example:
- *
  *    Rational(2).to_f      #=> 2.0
  *    Rational(9, 4).to_f   #=> 2.25
  *    Rational(-3, 4).to_f  #=> -0.75
@@ -1370,8 +1340,6 @@
  *
  * Returns self.
  *
- * For example:
- *
  *    Rational(2).to_r      #=> (2/1)
  *    Rational(-8, 6).to_r  #=> (-4/3)
  */
@@ -1486,8 +1454,6 @@
  * argument eps is given (rat-|eps| <= result <= rat+|eps|), self
  * otherwise.
  *
- * For example:
- *
  *    r = Rational(5033165, 16777216)
  *    r.rationalize                    #=> (5033165/16777216)
  *    r.rationalize(Rational('0.01'))  #=> (3/10)
@@ -1551,11 +1517,9 @@
  *
  * Returns the value as a string.
  *
- * For example:
- *
  *    Rational(2).to_s      #=> "2/1"
  *    Rational(-8, 6).to_s  #=> "-4/3"
- *    Rational('0.5').to_s  #=> "1/2"
+ *    Rational('1/2').to_s  #=> "1/2"
  */
 static VALUE
 nurat_to_s(VALUE self)
@@ -1569,11 +1533,9 @@
  *
  * Returns the value as a string for inspection.
  *
- * For example:
- *
  *    Rational(2).inspect      #=> "(2/1)"
  *    Rational(-8, 6).inspect  #=> "(-4/3)"
- *    Rational('0.5').inspect  #=> "(1/2)"
+ *    Rational('1/2').inspect  #=> "(1/2)"
  */
 static VALUE
 nurat_inspect(VALUE self)
@@ -1652,8 +1614,6 @@
  * Returns the greatest common divisor (always positive).  0.gcd(x)
  * and x.gcd(0) return abs(x).
  *
- * For example:
- *
  *    2.gcd(2)                    #=> 2
  *    3.gcd(-7)                   #=> 1
  *    ((1<<31)-1).gcd((1<<61)-1)  #=> 1
@@ -1672,8 +1632,6 @@
  * Returns the least common multiple (always positive).  0.lcm(x) and
  * x.lcm(0) return zero.
  *
- * For example:
- *
  *    2.lcm(2)                    #=> 2
  *    3.lcm(-7)                   #=> 21
  *    ((1<<31)-1).lcm((1<<61)-1)  #=> 4951760154835678088235319297
@@ -1691,8 +1649,6 @@
  *
  * Returns an array; [int.gcd(int2), int.lcm(int2)].
  *
- * For example:
- *
  *    2.gcdlcm(2)                    #=> [2, 2]
  *    3.gcdlcm(-7)                   #=> [1, 21]
  *    ((1<<31)-1).gcdlcm((1<<61)-1)  #=> [1, 4951760154835678088235319297]
@@ -1790,8 +1746,6 @@
  *
  * Returns the numerator.  The result is machine dependent.
  *
- * For example:
- *
  *    n = 0.3.numerator    #=> 5404319552844595
  *    d = 0.3.denominator  #=> 18014398509481984
  *    n.fdiv(d)            #=> 0.3
@@ -1855,8 +1809,6 @@
  *
  * Returns the value as a rational.
  *
- * For example:
- *
  *    1.to_r        #=> (1/1)
  *    (1<<64).to_r  #=> (18446744073709551616/1)
  */
@@ -1916,8 +1868,6 @@
  * NOTE: 0.3.to_r isn't the same as '0.3'.to_r.  The latter is
  * equivalent to '3/10'.to_r, but the former isn't so.
  *
- * For example:
- *
  *    2.0.to_r    #=> (2/1)
  *    2.5.to_r    #=> (5/2)
  *    -0.75.to_r  #=> (-3/4)
@@ -1953,8 +1903,6 @@
  * <= flt+|eps|).  if eps is not given, it will be chosen
  * automatically.
  *
- * For example:
- *
  *    0.3.rationalize          #=> (3/10)
  *    1.333.rationalize        #=> (1333/1000)
  *    1.333.rationalize(0.01)  #=> (4/3)
@@ -2155,8 +2103,6 @@
  * NOTE: '0.3'.to_r isn't the same as 0.3.to_r.  The former is
  * equivalent to '3/10'.to_r, but the latter isn't so.
  *
- * For example:
- *
  *    '  2  '.to_r       #=> (2/1)
  *    '300/2'.to_r       #=> (150/1)
  *    '-9.2'.to_r        #=> (-46/5)

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

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