mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Expanded f_numerator
This commit is contained in:
parent
34019a22eb
commit
ca524bcd49
3 changed files with 16 additions and 4 deletions
13
complex.c
13
complex.c
|
@ -191,6 +191,18 @@ f_arg(VALUE x)
|
|||
return rb_funcall(x, id_arg, 0);
|
||||
}
|
||||
|
||||
inline static VALUE
|
||||
f_numerator(VALUE x)
|
||||
{
|
||||
if (RB_TYPE_P(x, T_RATIONAL)) {
|
||||
return RRATIONAL(x)->num;
|
||||
}
|
||||
if (RB_FLOAT_TYPE_P(x)) {
|
||||
return rb_float_numerator(x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
inline static VALUE
|
||||
f_denominator(VALUE x)
|
||||
{
|
||||
|
@ -221,7 +233,6 @@ f_negate(VALUE x)
|
|||
return rb_funcall(x, id_negate, 0);
|
||||
}
|
||||
|
||||
fun1(numerator)
|
||||
fun1(real_p)
|
||||
|
||||
inline static VALUE
|
||||
|
|
|
@ -2029,6 +2029,7 @@ VALUE rb_rational_abs(VALUE self);
|
|||
VALUE rb_rational_cmp(VALUE self, VALUE other);
|
||||
VALUE rb_rational_pow(VALUE self, VALUE other);
|
||||
VALUE rb_numeric_quo(VALUE x, VALUE y);
|
||||
VALUE rb_float_numerator(VALUE x);
|
||||
VALUE rb_float_denominator(VALUE x);
|
||||
|
||||
/* re.c */
|
||||
|
|
|
@ -2057,8 +2057,8 @@ static VALUE float_to_r(VALUE self);
|
|||
*
|
||||
* See also Float#denominator.
|
||||
*/
|
||||
static VALUE
|
||||
float_numerator(VALUE self)
|
||||
VALUE
|
||||
rb_float_numerator(VALUE self)
|
||||
{
|
||||
double d = RFLOAT_VALUE(self);
|
||||
VALUE r;
|
||||
|
@ -2777,7 +2777,7 @@ Init_Rational(void)
|
|||
rb_define_method(rb_cInteger, "numerator", integer_numerator, 0);
|
||||
rb_define_method(rb_cInteger, "denominator", integer_denominator, 0);
|
||||
|
||||
rb_define_method(rb_cFloat, "numerator", float_numerator, 0);
|
||||
rb_define_method(rb_cFloat, "numerator", rb_float_numerator, 0);
|
||||
rb_define_method(rb_cFloat, "denominator", rb_float_denominator, 0);
|
||||
|
||||
rb_define_method(rb_cNilClass, "to_r", nilclass_to_r, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue