diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-29 12:23:55 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-29 12:23:55 +0000 |
commit | 292d6ee99f896a2afedc29136ff4216d948f19f3 (patch) | |
tree | 25d3abdfaa4bd1499f9f68c61deb6b050ea97cf2 | |
parent | e12b44e3756216eecf413647851c47bc4de6efa7 (diff) | |
download | ruby-292d6ee99f896a2afedc29136ff4216d948f19f3.tar.gz |
* numeric.c: Infinity.numerator returns self. [experimental]
* numeric.c: Infinity.denominator returns 1. [experimental]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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); |