From 548b5143db2c3d701520671ef1413cf3c39fcedf Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 12 Jun 2000 07:48:31 +0000 Subject: 2000-06-12 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index f84bdede1f..589f06bfc0 100644 --- a/numeric.c +++ b/numeric.c @@ -679,6 +679,40 @@ flo_zero_p(num) return Qfalse; } +static VALUE flo_is_nan_p(num) + VALUE num; +{ + + double value = RFLOAT(num)->value; + + return isnan(value) ? Qtrue : Qfalse; +} + +static VALUE flo_is_infinite_p(num) + VALUE num; +{ + double value = RFLOAT(num)->value; + + if (isinf(value)) { + return INT2FIX( value < 0 ? -1 : +1 ); + } + + return Qnil; +} + + +static VALUE flo_is_finite_p(num) + VALUE num; +{ + double value = RFLOAT(num)->value; + + if (isinf(value) || isnan(value)) + return Qfalse; + + return Qtrue; +} + + static VALUE to_integer(val) VALUE val; @@ -1570,4 +1604,8 @@ Init_Numeric() rb_define_method(rb_cFloat, "floor", flo_floor, 0); rb_define_method(rb_cFloat, "ceil", flo_ceil, 0); rb_define_method(rb_cFloat, "round", flo_round, 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); } -- cgit v1.2.3