diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | numeric.c | 20 |
2 files changed, 26 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Mon Dec 29 21:22:31 2008 Tadayoshi Funaba <tadf@dotrb.org> + + * numeric.c: Infinity.numerator returns self. [experimental] + + * numeric.c: Infinity.denominator returns 1. [experimental] + Mon Dec 29 20:57:14 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp> * man/ri.1: new manpage. @@ -1352,6 +1352,23 @@ 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: @@ -3247,6 +3264,9 @@ 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); |