summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-29 07:05:39 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-29 07:05:39 +0000
commit7ed0640ffb938fcf246f5167c7062fbf2a46dcd3 (patch)
tree03fe926eaafee97c67c833d82daa2137779b758f /numeric.c
parent92ab16fac66eeb9baba090af2976b27956ac56d4 (diff)
Add Float::INFINITY and Float::NAN.
* numeric.c (Init_Numeric): Add Float::INFINITY and Float::NAN. [ruby-dev:1657] [ruby-dev:4760] [ruby-list:7023] [ruby-list:46690] [ruby-core:26632] [ruby-talk:41352] [ruby-talk:203333] * include/ruby/defines.h (INFINITY): defined. * include/ruby/defines.h (NAN): defined. * include/ruby/util.h (ruby_div0): removed. * numeric.c (fix_pow): use INFINITY and NAN instead of ruby_div0(1.0). * marshal.c (r_object0): ditto. * bignum.c (big_fdiv): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/numeric.c b/numeric.c
index 11d67fef5d..319f7b2c48 100644
--- a/numeric.c
+++ b/numeric.c
@@ -63,6 +63,20 @@
#define DBL_EPSILON 2.2204460492503131e-16
#endif
+#ifdef HAVE_INFINITY
+#elif BYTE_ORDER == LITTLE_ENDIAN
+const unsigned char rb_infinity[] = "\x00\x00\x00\x00\x00\x00\xf0\x7f";
+#else
+const unsigned char rb_infinity[] = "\x7f\xf0\x00\x00\x00\x00\x00\x00";
+#endif
+
+#ifdef HAVE_NAN
+#elif BYTE_ORDER == LITTLE_ENDIAN
+const unsigned char rb_nan[] = "\x00\x00\x00\x00\x00\x00\xf8\x7f";
+#else
+const unsigned char rb_nan[] = "\x7f\xf8\x00\x00\x00\x00\x00\x00";
+#endif
+
extern double round(double);
#ifndef HAVE_ROUND
@@ -2467,8 +2481,6 @@ int_pow(long x, unsigned long y)
return LONG2NUM(z);
}
-#define infinite_value() ruby_div0(1.0)
-
/*
* call-seq:
* fix ** numeric -> numeric_result
@@ -2496,7 +2508,7 @@ fix_pow(VALUE x, VALUE y)
if (b == 1) return x;
if (a == 0) {
if (b > 0) return INT2FIX(0);
- return DBL2NUM(infinite_value());
+ return DBL2NUM(INFINITY);
}
if (a == 1) return INT2FIX(1);
if (a == -1) {
@@ -2524,7 +2536,7 @@ fix_pow(VALUE x, VALUE y)
case T_FLOAT:
if (RFLOAT_VALUE(y) == 0.0) return DBL2NUM(1.0);
if (a == 0) {
- return DBL2NUM(RFLOAT_VALUE(y) < 0 ? infinite_value() : 0.0);
+ return DBL2NUM(RFLOAT_VALUE(y) < 0 ? INFINITY : 0.0);
}
if (a == 1) return DBL2NUM(1.0);
{
@@ -3305,6 +3317,8 @@ Init_Numeric(void)
rb_define_const(rb_cFloat, "MIN", DBL2NUM(DBL_MIN));
rb_define_const(rb_cFloat, "MAX", DBL2NUM(DBL_MAX));
rb_define_const(rb_cFloat, "EPSILON", DBL2NUM(DBL_EPSILON));
+ rb_define_const(rb_cFloat, "INFINITY", DBL2NUM(INFINITY));
+ rb_define_const(rb_cFloat, "NAN", DBL2NUM(NAN));
rb_define_method(rb_cFloat, "to_s", flo_to_s, 0);
rb_define_method(rb_cFloat, "coerce", flo_coerce, 1);