due to conflict

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2009-06-19 13:37:04 +00:00
parent cb699fc930
commit f86ad72d2a
3 changed files with 277 additions and 223 deletions

View File

@ -1,3 +1,18 @@
Fri Jun 19 22:21:17 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c: edited rdoc.
Fri Jun 19 21:56:01 2009 Tadayoshi Funaba <tadf@dotrb.org>
* rational.c (nurat_expt): delegates to complex when self is
negative. bacause Float#** does not produce complex.
Fri Jun 19 21:40:58 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c: edited rdoc.
* rational.c: ditto.
Fri Jun 19 20:53:54 2009 Yukihiro Matsumoto <matz@ruby-lang.org> Fri Jun 19 20:53:54 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* encoding.c (rb_enc_name_list): update RDoc. [ruby-core:23926] * encoding.c (rb_enc_name_list): update RDoc. [ruby-core:23926]

View File

@ -289,8 +289,13 @@ static VALUE num_floor(VALUE num);
* num.div(numeric) => integer * num.div(numeric) => integer
* *
* Uses <code>/</code> to perform division, then converts the result to * Uses <code>/</code> to perform division, then converts the result to
* an integer. <code>Numeric</code> does not define the <code>/</code> * an integer. <code>numeric</code> does not define the <code>/</code>
* operator; this is left to subclasses. * operator; this is left to subclasses.
*
* Equivalent to
* <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[0]</code>.
*
* See <code>Numeric#divmod</code>.
*/ */
static VALUE static VALUE
@ -303,13 +308,13 @@ num_div(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* num.divmod( aNumeric ) -> anArray * num.divmod(numeric) => array
* *
* Returns an array containing the quotient and modulus obtained by * Returns an array containing the quotient and modulus obtained by
* dividing <i>num</i> by <i>aNumeric</i>. If <code>q, r = * dividing <i>num</i> by <i>numeric</i>. If <code>q, r =
* x.divmod(y)</code>, then * x.divmod(y)</code>, then
* *
* q = floor(float(x)/float(y)) * q = floor(x/y)
* x = q*y+r * x = q*y+r
* *
* The quotient is rounded toward -infinity, as shown in the following table: * The quotient is rounded toward -infinity, as shown in the following table:
@ -352,8 +357,12 @@ num_divmod(VALUE x, VALUE y)
* call-seq: * call-seq:
* num.modulo(numeric) => result * num.modulo(numeric) => result
* *
* x.modulo(y) means x-y*(x/y).floor
*
* Equivalent to * Equivalent to
* <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[1]</code>. * <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[1]</code>.
*
* See <code>Numeric#divmod</code>.
*/ */
static VALUE static VALUE
@ -366,12 +375,9 @@ num_modulo(VALUE x, VALUE y)
* call-seq: * call-seq:
* num.remainder(numeric) => result * num.remainder(numeric) => result
* *
* If <i>num</i> and <i>numeric</i> have different signs, returns * x.remainder(y) means x-y*(x/y).truncate
* <em>mod</em>-<i>numeric</i>; otherwise, returns <em>mod</em>. In *
* both cases <em>mod</em> is the value * See <code>Numeric#divmod</code>.
* <i>num</i>.<code>modulo(</code><i>numeric</i><code>)</code>. The
* differences between <code>remainder</code> and modulo
* (<code>%</code>) are shown in the table under <code>Numeric#divmod</code>.
*/ */
static VALUE static VALUE
@ -391,7 +397,7 @@ num_remainder(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* num.real? -> true or false * num.real? => true or false
* *
* Returns <code>true</code> if <i>num</i> is a <code>Real</code> * Returns <code>true</code> if <i>num</i> is a <code>Real</code>
* (i.e. non <code>Complex</code>). * (i.e. non <code>Complex</code>).
@ -405,7 +411,7 @@ num_real_p(VALUE num)
/* /*
* call-seq: * call-seq:
* num.integer? -> true or false * num.integer? => true or false
* *
* Returns <code>true</code> if <i>num</i> is an <code>Integer</code> * Returns <code>true</code> if <i>num</i> is an <code>Integer</code>
* (including <code>Fixnum</code> and <code>Bignum</code>). * (including <code>Fixnum</code> and <code>Bignum</code>).
@ -834,7 +840,7 @@ num_eql(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* num <=> other -> 0 or nil * num <=> other => 0 or nil
* *
* Returns zero if <i>num</i> equals <i>other</i>, <code>nil</code> * Returns zero if <i>num</i> equals <i>other</i>, <code>nil</code>
* otherwise. * otherwise.
@ -1148,7 +1154,7 @@ flo_eql(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* flt.to_f => flt * flt.to_f => self
* *
* As <code>flt</code> is already a float, returns <i>self</i>. * As <code>flt</code> is already a float, returns <i>self</i>.
*/ */
@ -1179,7 +1185,7 @@ flo_abs(VALUE flt)
/* /*
* call-seq: * call-seq:
* flt.zero? -> true or false * flt.zero? => true or false
* *
* Returns <code>true</code> if <i>flt</i> is 0.0. * Returns <code>true</code> if <i>flt</i> is 0.0.
* *
@ -1196,7 +1202,7 @@ flo_zero_p(VALUE num)
/* /*
* call-seq: * call-seq:
* flt.nan? -> true or false * flt.nan? => true or false
* *
* Returns <code>true</code> if <i>flt</i> is an invalid IEEE floating * Returns <code>true</code> if <i>flt</i> is an invalid IEEE floating
* point number. * point number.
@ -1217,7 +1223,7 @@ flo_is_nan_p(VALUE num)
/* /*
* call-seq: * call-seq:
* flt.infinite? -> nil, -1, +1 * flt.infinite? => nil, -1, +1
* *
* Returns <code>nil</code>, -1, or +1 depending on whether <i>flt</i> * Returns <code>nil</code>, -1, or +1 depending on whether <i>flt</i>
* is finite, -infinity, or +infinity. * is finite, -infinity, or +infinity.
@ -1241,7 +1247,7 @@ flo_is_infinite_p(VALUE num)
/* /*
* call-seq: * call-seq:
* flt.finite? -> true or false * flt.finite? => true or false
* *
* Returns <code>true</code> if <i>flt</i> is a valid IEEE floating * Returns <code>true</code> if <i>flt</i> is a valid IEEE floating
* point number (it is not infinite, and <code>nan?</code> is * point number (it is not infinite, and <code>nan?</code> is
@ -1492,7 +1498,7 @@ ruby_float_step(VALUE from, VALUE to, VALUE step, int excl)
/* /*
* call-seq: * call-seq:
* num.step(limit, step ) {|i| block } => num * num.step(limit, step ) {|i| block } => self
* *
* Invokes <em>block</em> with the sequence of numbers starting at * Invokes <em>block</em> with the sequence of numbers starting at
* <i>num</i>, incremented by <i>step</i> on each call. The loop * <i>num</i>, incremented by <i>step</i> on each call. The loop
@ -1807,7 +1813,7 @@ int_to_i(VALUE num)
/* /*
* call-seq: * call-seq:
* int.integer? -> true * int.integer? => true
* *
* Always returns <code>true</code>. * Always returns <code>true</code>.
*/ */
@ -1820,7 +1826,7 @@ int_int_p(VALUE num)
/* /*
* call-seq: * call-seq:
* int.odd? -> true or false * int.odd? => true or false
* *
* Returns <code>true</code> if <i>int</i> is an odd number. * Returns <code>true</code> if <i>int</i> is an odd number.
*/ */
@ -1836,7 +1842,7 @@ int_odd_p(VALUE num)
/* /*
* call-seq: * call-seq:
* int.even? -> true or false * int.even? => true or false
* *
* Returns <code>true</code> if <i>int</i> is an even number. * Returns <code>true</code> if <i>int</i> is an even number.
*/ */
@ -1962,7 +1968,7 @@ int_chr(int argc, VALUE *argv, VALUE num)
/* /*
* call-seq: * call-seq:
* int.ord => int * int.ord => self
* *
* Returns the int itself. * Returns the int itself.
* *
@ -2043,7 +2049,7 @@ rb_fix2str(VALUE x, int base)
/* /*
* call-seq: * call-seq:
* fix.to_s( base=10 ) -> aString * fix.to_s(base=10) => string
* *
* Returns a string containing the representation of <i>fix</i> radix * Returns a string containing the representation of <i>fix</i> radix
* <i>base</i> (between 2 and 36). * <i>base</i> (between 2 and 36).
@ -2304,7 +2310,7 @@ fix_div(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* fix.div(numeric) => numeric_result * fix.div(numeric) => integer
* *
* Performs integer division: returns integer value. * Performs integer division: returns integer value.
*/ */
@ -2317,11 +2323,11 @@ fix_idiv(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* fix % other => Numeric * fix % other => numeric
* fix.modulo(other) => Numeric * fix.modulo(other) => numeric
* *
* Returns <code>fix</code> modulo <code>other</code>. * Returns <code>fix</code> modulo <code>other</code>.
* See <code>Numeric.divmod</code> for more information. * See <code>numeric.divmod</code> for more information.
*/ */
static VALUE static VALUE
@ -2424,7 +2430,7 @@ int_pow(long x, unsigned long y)
/* /*
* call-seq: * call-seq:
* fix ** other => Numeric * fix ** other => numeric
* *
* Raises <code>fix</code> to the <code>other</code> power, which may * Raises <code>fix</code> to the <code>other</code> power, which may
* be negative or fractional. * be negative or fractional.
@ -2488,7 +2494,7 @@ fix_pow(VALUE x, VALUE y)
/* /*
* call-seq: * call-seq:
* fix == other * fix == other => true or false
* *
* Return <code>true</code> if <code>fix</code> equals <code>other</code> * Return <code>true</code> if <code>fix</code> equals <code>other</code>
* numerically. * numerically.
@ -2837,7 +2843,7 @@ fix_aref(VALUE fix, VALUE idx)
/* /*
* call-seq: * call-seq:
* fix.to_f -> float * fix.to_f => float
* *
* Converts <i>fix</i> to a <code>Float</code>. * Converts <i>fix</i> to a <code>Float</code>.
* *
@ -2855,7 +2861,7 @@ fix_to_f(VALUE num)
/* /*
* call-seq: * call-seq:
* fix.abs -> aFixnum * fix.abs => fix
* *
* Returns the absolute value of <i>fix</i>. * Returns the absolute value of <i>fix</i>.
* *
@ -2878,7 +2884,7 @@ fix_abs(VALUE fix)
/* /*
* call-seq: * call-seq:
* fix.size -> fixnum * fix.size => fixnum
* *
* Returns the number of <em>bytes</em> in the machine representation * Returns the number of <em>bytes</em> in the machine representation
* of a <code>Fixnum</code>. * of a <code>Fixnum</code>.
@ -2896,7 +2902,7 @@ fix_size(VALUE fix)
/* /*
* call-seq: * call-seq:
* int.upto(limit) {|i| block } => int * int.upto(limit) {|i| block } => self
* *
* Iterates <em>block</em>, passing in integer values from <i>int</i> * Iterates <em>block</em>, passing in integer values from <i>int</i>
* up to and including <i>limit</i>. * up to and including <i>limit</i>.
@ -2934,7 +2940,7 @@ int_upto(VALUE from, VALUE to)
/* /*
* call-seq: * call-seq:
* int.downto(limit) {|i| block } => int * int.downto(limit) {|i| block } => self
* *
* Iterates <em>block</em>, passing decreasing values from <i>int</i> * Iterates <em>block</em>, passing decreasing values from <i>int</i>
* down to and including <i>limit</i>. * down to and including <i>limit</i>.
@ -2973,7 +2979,7 @@ int_downto(VALUE from, VALUE to)
/* /*
* call-seq: * call-seq:
* int.times {|i| block } => int * int.times {|i| block } => self
* *
* Iterates block <i>int</i> times, passing in values from zero to * Iterates block <i>int</i> times, passing in values from zero to
* <i>int</i> - 1. * <i>int</i> - 1.
@ -3068,7 +3074,7 @@ fix_zero_p(VALUE num)
/* /*
* call-seq: * call-seq:
* fix.odd? -> true or false * fix.odd? => true or false
* *
* Returns <code>true</code> if <i>fix</i> is an odd number. * Returns <code>true</code> if <i>fix</i> is an odd number.
*/ */
@ -3084,7 +3090,7 @@ fix_odd_p(VALUE num)
/* /*
* call-seq: * call-seq:
* fix.even? -> true or false * fix.even? => true or false
* *
* Returns <code>true</code> if <i>fix</i> is an even number. * Returns <code>true</code> if <i>fix</i> is an even number.
*/ */

View File

@ -529,7 +529,6 @@ nurat_numerator(VALUE self)
return dat->num; return dat->num;
} }
/* /*
* call-seq: * call-seq:
* rat.denominator => integer * rat.denominator => integer
@ -906,7 +905,7 @@ nurat_fdiv(VALUE self, VALUE other)
* *
* Rational(2, 3) ** Rational(2, 3) #=> 0.7631428283688879 * Rational(2, 3) ** Rational(2, 3) #=> 0.7631428283688879
* Rational(900) ** Rational(1) #=> (900/1) * Rational(900) ** Rational(1) #=> (900/1)
* Rational(-2, 9) ** Rational(-9, 2) #=> NaN * Rational(-2, 9) ** Rational(-9, 2) #=> (4.793639101185069e-13-869.8739233809262i)
* Rational(9, 8) ** 4 #=> (6561/4096) * Rational(9, 8) ** 4 #=> (6561/4096)
* Rational(20, 9) ** 9.8 #=> 2503.325740344559 * Rational(20, 9) ** 9.8 #=> 2503.325740344559
* Rational(3, 2) ** 2**3 #=> (6561/256) * Rational(3, 2) ** 2**3 #=> (6561/256)
@ -952,6 +951,8 @@ nurat_expt(VALUE self, VALUE other)
} }
case T_FLOAT: case T_FLOAT:
case T_RATIONAL: case T_RATIONAL:
if (f_negative_p(self))
return f_expt(rb_complex_new1(self), other); /* explicitly */
return f_expt(f_to_f(self), other); return f_expt(f_to_f(self), other);
default: default:
return rb_num_coerce_bin(self, other, id_expt); return rb_num_coerce_bin(self, other, id_expt);
@ -1143,9 +1144,9 @@ nurat_idiv(VALUE self, VALUE other)
* rat.modulo(numeric) => numeric * rat.modulo(numeric) => numeric
* rat % numeric => numeric * rat % numeric => numeric
* *
* Returns the modulo of _rat_ and _numeric_ as a +Numeric+ object, i.e.: * Returns the modulo of _rat_ and _numeric_ as a +Numeric+ object.
* *
* _rat_-_numeric_*(rat/numeric).floor * x.modulo(y) means x-y*(x/y).floor
* *
* A +TypeError+ is raised unless _numeric_ is a +Numeric+ object. A * A +TypeError+ is raised unless _numeric_ is a +Numeric+ object. A
* +ZeroDivisionError+ is raised if _numeric_ is 0. A +FloatDomainError+ is * +ZeroDivisionError+ is raised if _numeric_ is 0. A +FloatDomainError+ is
@ -1167,7 +1168,6 @@ nurat_mod(VALUE self, VALUE other)
return f_sub(self, f_mul(other, val)); return f_sub(self, f_mul(other, val));
} }
/* /*
* call-seq: * call-seq:
* rat.divmod(numeric) => array * rat.divmod(numeric) => array
@ -1206,12 +1206,12 @@ nurat_quot(VALUE self, VALUE other)
#endif #endif
/* /*
* call-seq: rat.remainder(numeric) => numeric_result * call-seq:
* rat.remainder(numeric) => numeric_result
* *
* Returns the remainder of dividing _rat_ by _numeric_ as a +Numeric+ object, * Returns the remainder of dividing _rat_ by _numeric_ as a +Numeric+ object.
* i.e.:
* *
* _rat_-_numeric_*(_rat_/_numeric_).truncate * x.remainder(y) means x-y*(x/y).truncate
* *
* A +ZeroDivisionError+ is raised if _numeric_ is 0. A +FloatDomainError+ is * A +ZeroDivisionError+ is raised if _numeric_ is 0. A +FloatDomainError+ is
* raised if the result is Infinity or NaN, or _numeric_ is 0.0. A +TypeError+ * raised if the result is Infinity or NaN, or _numeric_ is 0.0. A +TypeError+
@ -1296,6 +1296,9 @@ nurat_ceil(VALUE self)
* *
* Returns _rat_ truncated to an integer as an +Integer+ object. * Returns _rat_ truncated to an integer as an +Integer+ object.
* *
* Equivalent to
* <i>rat</i>.<code>truncate(</code>.
*
* For example: * For example:
* *
* Rational(2, 3).to_i #=> 0 * Rational(2, 3).to_i #=> 0
@ -1748,6 +1751,12 @@ rb_Rational(VALUE x, VALUE y)
#define id_to_r rb_intern("to_r") #define id_to_r rb_intern("to_r")
#define f_to_r(x) rb_funcall(x, id_to_r, 0) #define f_to_r(x) rb_funcall(x, id_to_r, 0)
/*
* call-seq:
* num.numerator => integer
*
* Returns the numerator of _num_ as an +Integer+ object.
*/
static VALUE static VALUE
numeric_numerator(VALUE self) numeric_numerator(VALUE self)
{ {
@ -1760,18 +1769,36 @@ numeric_denominator(VALUE self)
return f_denominator(f_to_r(self)); return f_denominator(f_to_r(self));
} }
/*
* call-seq:
* int.numerator => self
*
* Returns self.
*/
static VALUE static VALUE
integer_numerator(VALUE self) integer_numerator(VALUE self)
{ {
return self; return self;
} }
/*
* call-seq:
* int.numerator => 1
*
* Returns 1.
*/
static VALUE static VALUE
integer_denominator(VALUE self) integer_denominator(VALUE self)
{ {
return INT2FIX(1); return INT2FIX(1);
} }
/*
* call-seq:
* flo.numerator => integer
*
* Returns the numerator of _flo_ as an +Integer+ object.
*/
static VALUE static VALUE
float_numerator(VALUE self) float_numerator(VALUE self)
{ {
@ -1781,6 +1808,12 @@ float_numerator(VALUE self)
return rb_call_super(0, 0); return rb_call_super(0, 0);
} }
/*
* call-seq:
* flo.denominator => integer
*
* Returns the denominator of _flo_ as an +Integer+ object.
*/
static VALUE static VALUE
float_denominator(VALUE self) float_denominator(VALUE self)
{ {