diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-12 07:48:31 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-12 07:48:31 +0000 |
commit | 2bc48ec00f2ee0028c1a5096aa676391820b87ec (patch) | |
tree | f89e9e7746e75343a2886ee50fc23a37f9fe5886 /numeric.c | |
parent | ce6c53d24d361f589169ffa49360e93be8c994a3 (diff) | |
download | ruby-2bc48ec00f2ee0028c1a5096aa676391820b87ec.tar.gz ruby-2bc48ec00f2ee0028c1a5096aa676391820b87ec.tar.xz ruby-2bc48ec00f2ee0028c1a5096aa676391820b87ec.zip |
2000-06-12
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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); } |