summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-12 07:48:31 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-12 07:48:31 +0000
commit548b5143db2c3d701520671ef1413cf3c39fcedf (patch)
treef89e9e7746e75343a2886ee50fc23a37f9fe5886 /numeric.c
parentcfdf994071fac150246d54d65a66ddeba4d53a97 (diff)
2000-06-12
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c38
1 files changed, 38 insertions, 0 deletions
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);
}