mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
cb699fc930
commit
f86ad72d2a
3 changed files with 277 additions and 223 deletions
15
ChangeLog
15
ChangeLog
|
@ -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>
|
||||
|
||||
* encoding.c (rb_enc_name_list): update RDoc. [ruby-core:23926]
|
||||
|
|
84
numeric.c
84
numeric.c
|
@ -289,8 +289,13 @@ static VALUE num_floor(VALUE num);
|
|||
* num.div(numeric) => integer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Equivalent to
|
||||
* <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[0]</code>.
|
||||
*
|
||||
* See <code>Numeric#divmod</code>.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -303,14 +308,14 @@ num_div(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.divmod( aNumeric ) -> anArray
|
||||
* num.divmod(numeric) => array
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* q = floor(float(x)/float(y))
|
||||
* x = q*y + r
|
||||
* q = floor(x/y)
|
||||
* x = q*y+r
|
||||
*
|
||||
* The quotient is rounded toward -infinity, as shown in the following table:
|
||||
*
|
||||
|
@ -352,8 +357,12 @@ num_divmod(VALUE x, VALUE y)
|
|||
* call-seq:
|
||||
* num.modulo(numeric) => result
|
||||
*
|
||||
* x.modulo(y) means x-y*(x/y).floor
|
||||
*
|
||||
* Equivalent to
|
||||
* <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[1]</code>.
|
||||
*
|
||||
* See <code>Numeric#divmod</code>.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -366,12 +375,9 @@ num_modulo(VALUE x, VALUE y)
|
|||
* call-seq:
|
||||
* num.remainder(numeric) => result
|
||||
*
|
||||
* If <i>num</i> and <i>numeric</i> have different signs, returns
|
||||
* <em>mod</em>-<i>numeric</i>; otherwise, returns <em>mod</em>. In
|
||||
* both cases <em>mod</em> is the value
|
||||
* <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>.
|
||||
* x.remainder(y) means x-y*(x/y).truncate
|
||||
*
|
||||
* See <code>Numeric#divmod</code>.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -391,7 +397,7 @@ num_remainder(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* (i.e. non <code>Complex</code>).
|
||||
|
@ -405,7 +411,7 @@ num_real_p(VALUE num)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* (including <code>Fixnum</code> and <code>Bignum</code>).
|
||||
|
@ -834,7 +840,7 @@ num_eql(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* otherwise.
|
||||
|
@ -1148,7 +1154,7 @@ flo_eql(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* flt.to_f => flt
|
||||
* flt.to_f => self
|
||||
*
|
||||
* As <code>flt</code> is already a float, returns <i>self</i>.
|
||||
*/
|
||||
|
@ -1179,7 +1185,7 @@ flo_abs(VALUE flt)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* flt.zero? -> true or false
|
||||
* flt.zero? => true or false
|
||||
*
|
||||
* Returns <code>true</code> if <i>flt</i> is 0.0.
|
||||
*
|
||||
|
@ -1196,7 +1202,7 @@ flo_zero_p(VALUE num)
|
|||
|
||||
/*
|
||||
* 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
|
||||
* point number.
|
||||
|
@ -1217,7 +1223,7 @@ flo_is_nan_p(VALUE num)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* is finite, -infinity, or +infinity.
|
||||
|
@ -1241,7 +1247,7 @@ flo_is_infinite_p(VALUE num)
|
|||
|
||||
/*
|
||||
* 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
|
||||
* 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:
|
||||
* 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
|
||||
* <i>num</i>, incremented by <i>step</i> on each call. The loop
|
||||
|
@ -1807,7 +1813,7 @@ int_to_i(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.integer? -> true
|
||||
* int.integer? => true
|
||||
*
|
||||
* Always returns <code>true</code>.
|
||||
*/
|
||||
|
@ -1820,7 +1826,7 @@ int_int_p(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.odd? -> true or false
|
||||
* int.odd? => true or false
|
||||
*
|
||||
* Returns <code>true</code> if <i>int</i> is an odd number.
|
||||
*/
|
||||
|
@ -1836,7 +1842,7 @@ int_odd_p(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.even? -> true or false
|
||||
* int.even? => true or false
|
||||
*
|
||||
* 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:
|
||||
* int.ord => int
|
||||
* int.ord => self
|
||||
*
|
||||
* Returns the int itself.
|
||||
*
|
||||
|
@ -2043,7 +2049,7 @@ rb_fix2str(VALUE x, int base)
|
|||
|
||||
/*
|
||||
* 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
|
||||
* <i>base</i> (between 2 and 36).
|
||||
|
@ -2304,7 +2310,7 @@ fix_div(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.div(numeric) => numeric_result
|
||||
* fix.div(numeric) => integer
|
||||
*
|
||||
* Performs integer division: returns integer value.
|
||||
*/
|
||||
|
@ -2317,11 +2323,11 @@ fix_idiv(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix % other => Numeric
|
||||
* fix.modulo(other) => Numeric
|
||||
* fix % other => numeric
|
||||
* fix.modulo(other) => numeric
|
||||
*
|
||||
* 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
|
||||
|
@ -2424,7 +2430,7 @@ int_pow(long x, unsigned long y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix ** other => Numeric
|
||||
* fix ** other => numeric
|
||||
*
|
||||
* Raises <code>fix</code> to the <code>other</code> power, which may
|
||||
* be negative or fractional.
|
||||
|
@ -2488,7 +2494,7 @@ fix_pow(VALUE x, VALUE y)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix == other
|
||||
* fix == other => true or false
|
||||
*
|
||||
* Return <code>true</code> if <code>fix</code> equals <code>other</code>
|
||||
* numerically.
|
||||
|
@ -2837,7 +2843,7 @@ fix_aref(VALUE fix, VALUE idx)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.to_f -> float
|
||||
* fix.to_f => float
|
||||
*
|
||||
* Converts <i>fix</i> to a <code>Float</code>.
|
||||
*
|
||||
|
@ -2855,7 +2861,7 @@ fix_to_f(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.abs -> aFixnum
|
||||
* fix.abs => fix
|
||||
*
|
||||
* Returns the absolute value of <i>fix</i>.
|
||||
*
|
||||
|
@ -2878,7 +2884,7 @@ fix_abs(VALUE fix)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.size -> fixnum
|
||||
* fix.size => fixnum
|
||||
*
|
||||
* Returns the number of <em>bytes</em> in the machine representation
|
||||
* of a <code>Fixnum</code>.
|
||||
|
@ -2896,7 +2902,7 @@ fix_size(VALUE fix)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* up to and including <i>limit</i>.
|
||||
|
@ -2934,7 +2940,7 @@ int_upto(VALUE from, VALUE to)
|
|||
|
||||
/*
|
||||
* 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>
|
||||
* down to and including <i>limit</i>.
|
||||
|
@ -2973,7 +2979,7 @@ int_downto(VALUE from, VALUE to)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.times {|i| block } => int
|
||||
* int.times {|i| block } => self
|
||||
*
|
||||
* Iterates block <i>int</i> times, passing in values from zero to
|
||||
* <i>int</i> - 1.
|
||||
|
@ -3068,7 +3074,7 @@ fix_zero_p(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.odd? -> true or false
|
||||
* fix.odd? => true or false
|
||||
*
|
||||
* Returns <code>true</code> if <i>fix</i> is an odd number.
|
||||
*/
|
||||
|
@ -3084,7 +3090,7 @@ fix_odd_p(VALUE num)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* fix.even? -> true or false
|
||||
* fix.even? => true or false
|
||||
*
|
||||
* Returns <code>true</code> if <i>fix</i> is an even number.
|
||||
*/
|
||||
|
|
51
rational.c
51
rational.c
|
@ -529,7 +529,6 @@ nurat_numerator(VALUE self)
|
|||
return dat->num;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* rat.denominator => integer
|
||||
|
@ -906,7 +905,7 @@ nurat_fdiv(VALUE self, VALUE other)
|
|||
*
|
||||
* Rational(2, 3) ** Rational(2, 3) #=> 0.7631428283688879
|
||||
* 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(20, 9) ** 9.8 #=> 2503.325740344559
|
||||
* Rational(3, 2) ** 2**3 #=> (6561/256)
|
||||
|
@ -952,6 +951,8 @@ nurat_expt(VALUE self, VALUE other)
|
|||
}
|
||||
case T_FLOAT:
|
||||
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);
|
||||
default:
|
||||
return rb_num_coerce_bin(self, other, id_expt);
|
||||
|
@ -1143,9 +1144,9 @@ nurat_idiv(VALUE self, VALUE other)
|
|||
* rat.modulo(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
|
||||
* +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));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* rat.divmod(numeric) => array
|
||||
|
@ -1206,12 +1206,12 @@ nurat_quot(VALUE self, VALUE other)
|
|||
#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,
|
||||
* i.e.:
|
||||
* Returns the remainder of dividing _rat_ by _numeric_ as a +Numeric+ object.
|
||||
*
|
||||
* _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
|
||||
* 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.
|
||||
*
|
||||
* Equivalent to
|
||||
* <i>rat</i>.<code>truncate(</code>.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* 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 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
|
||||
numeric_numerator(VALUE self)
|
||||
{
|
||||
|
@ -1760,18 +1769,36 @@ numeric_denominator(VALUE self)
|
|||
return f_denominator(f_to_r(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.numerator => self
|
||||
*
|
||||
* Returns self.
|
||||
*/
|
||||
static VALUE
|
||||
integer_numerator(VALUE self)
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* int.numerator => 1
|
||||
*
|
||||
* Returns 1.
|
||||
*/
|
||||
static VALUE
|
||||
integer_denominator(VALUE self)
|
||||
{
|
||||
return INT2FIX(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* flo.numerator => integer
|
||||
*
|
||||
* Returns the numerator of _flo_ as an +Integer+ object.
|
||||
*/
|
||||
static VALUE
|
||||
float_numerator(VALUE self)
|
||||
{
|
||||
|
@ -1781,6 +1808,12 @@ float_numerator(VALUE self)
|
|||
return rb_call_super(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* flo.denominator => integer
|
||||
*
|
||||
* Returns the denominator of _flo_ as an +Integer+ object.
|
||||
*/
|
||||
static VALUE
|
||||
float_denominator(VALUE self)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue