* numeric.c (*_numerator,*_denominator): moved to rational.c.

* rational.c (*_numerator,*_denominator): moved from numeric.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2009-06-19 00:31:08 +00:00
Родитель 44a1d99635
Коммит 5134783cde
3 изменённых файлов: 66 добавлений и 53 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Fri Jun 19 09:28:45 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c (*_numerator,*_denominator): moved to rational.c.
* rational.c (*_numerator,*_denominator): moved from numeric.c.
Fri Jun 19 08:14:07 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (big_lshift, big_rshift): return Bignum always withou

Просмотреть файл

@ -1384,24 +1384,6 @@ flo_truncate(VALUE num)
return LONG2FIX(val);
}
static VALUE
flo_numerator(VALUE num)
{
double d = RFLOAT_VALUE(num);
if (isinf(d) || isnan(d))
return num;
return rb_call_super(0, 0);
}
static VALUE
flo_denominator(VALUE num)
{
double d = RFLOAT_VALUE(num);
if (isinf(d) || isnan(d))
return INT2FIX(1);
return rb_call_super(0, 0);
}
/*
* call-seq:
* num.floor => integer
@ -1789,20 +1771,6 @@ rb_num2ull(VALUE val)
#endif /* HAVE_LONG_LONG */
static VALUE
num_numerator(VALUE num)
{
return rb_funcall(rb_funcall(num, rb_intern("to_r"), 0),
rb_intern("numerator"), 0);
}
static VALUE
num_denominator(VALUE num)
{
return rb_funcall(rb_funcall(num, rb_intern("to_r"), 0),
rb_intern("denominator"), 0);
}
/*
* Document-class: Integer
*
@ -2006,18 +1974,6 @@ int_ord(num)
return num;
}
static VALUE
int_numerator(VALUE num)
{
return num;
}
static VALUE
int_denominator(VALUE num)
{
return INT2FIX(1);
}
/********************************************************************
*
* Document-class: Fixnum
@ -3190,9 +3146,6 @@ Init_Numeric(void)
rb_define_method(rb_cNumeric, "truncate", num_truncate, 0);
rb_define_method(rb_cNumeric, "step", num_step, -1);
rb_define_method(rb_cNumeric, "numerator", num_numerator, 0);
rb_define_method(rb_cNumeric, "denominator", num_denominator, 0);
rb_cInteger = rb_define_class("Integer", rb_cNumeric);
rb_undef_alloc_func(rb_cInteger);
rb_undef_method(CLASS_OF(rb_cInteger), "new");
@ -3215,9 +3168,6 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "truncate", int_to_i, 0);
rb_define_method(rb_cInteger, "round", int_round, -1);
rb_define_method(rb_cInteger, "numerator", int_numerator, 0);
rb_define_method(rb_cInteger, "denominator", int_denominator, 0);
rb_cFixnum = rb_define_class("Fixnum", rb_cInteger);
rb_define_method(rb_cFixnum, "to_s", fix_to_s, -1);
@ -3310,9 +3260,6 @@ Init_Numeric(void)
rb_define_method(rb_cFloat, "round", flo_round, -1);
rb_define_method(rb_cFloat, "truncate", flo_truncate, 0);
rb_define_method(rb_cFloat, "numerator", flo_numerator, 0);
rb_define_method(rb_cFloat, "denominator", flo_denominator, 0);
rb_define_method(rb_cFloat, "nan?", flo_is_nan_p, 0);
rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);
rb_define_method(rb_cFloat, "finite?", flo_is_finite_p, 0);

Просмотреть файл

@ -1202,6 +1202,57 @@ rb_Rational(VALUE x, VALUE y)
return nurat_s_convert(2, a, rb_cRational);
}
#define id_numerator rb_intern("numerator")
#define f_numerator(x) rb_funcall(x, id_numerator, 0)
#define id_denominator rb_intern("denominator")
#define f_denominator(x) rb_funcall(x, id_denominator, 0)
#define id_to_r rb_intern("to_r")
#define f_to_r(x) rb_funcall(x, id_to_r, 0)
static VALUE
numeric_numerator(VALUE self)
{
return f_numerator(f_to_r(self));
}
static VALUE
numeric_denominator(VALUE self)
{
return f_denominator(f_to_r(self));
}
static VALUE
integer_numerator(VALUE self)
{
return self;
}
static VALUE
integer_denominator(VALUE self)
{
return INT2FIX(1);
}
static VALUE
float_numerator(VALUE self)
{
double d = RFLOAT_VALUE(self);
if (isinf(d) || isnan(d))
return self;
return rb_call_super(0, 0);
}
static VALUE
float_denominator(VALUE self)
{
double d = RFLOAT_VALUE(self);
if (isinf(d) || isnan(d))
return INT2FIX(1);
return rb_call_super(0, 0);
}
static VALUE
nilclass_to_r(VALUE self)
{
@ -1579,6 +1630,15 @@ Init_Rational(void)
rb_define_method(rb_cInteger, "lcm", rb_lcm, 1);
rb_define_method(rb_cInteger, "gcdlcm", rb_gcdlcm, 1);
rb_define_method(rb_cNumeric, "numerator", numeric_numerator, 0);
rb_define_method(rb_cNumeric, "denominator", numeric_denominator, 0);
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, "denominator", float_denominator, 0);
rb_define_method(rb_cNilClass, "to_r", nilclass_to_r, 0);
rb_define_method(rb_cInteger, "to_r", integer_to_r, 0);
rb_define_method(rb_cFloat, "to_r", float_to_r, 0);