summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-31 22:54:40 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-31 22:54:40 +0000
commit5d612b96add0931a04f678aef8f560d5bd580445 (patch)
treecc0c9a39158a97e59f9517d7be8d971adf37506b
parent8dadafa2406328a7637270d411e65ac4b6b465d2 (diff)
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): returns Inf if
exp is bigger than DBL_MANT_DIG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@23611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/bigdecimal/bigdecimal.c6
2 files changed, 9 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index dbecd88281..c02514e13f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Jun 1 07:20:02 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): returns Inf if
+ exp is bigger than DBL_MANT_DIG.
+
Sun May 31 23:28:00 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_makefile): checks for duplication of source
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index bbc7953b87..5cb4d95fab 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -592,14 +592,16 @@ BigDecimal_to_f(VALUE self)
GUARD_OBJ(p,GetVpValue(self,1));
if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d);
+ if (e > DBL_MAX_10_EXP) goto erange;
buf = ALLOCA_N(char,(unsigned int)VpNumOfChars(p,"E"));
VpToString(p, buf, 0, 0);
errno = 0;
d = strtod(buf, 0);
if(errno == ERANGE) {
+ erange:
VpException(VP_EXCEPTION_OVERFLOW,"BigDecimal to Float conversion",0);
- if(d>0.0) return rb_float_new(DBL_MAX);
- else return rb_float_new(-DBL_MAX);
+ if(d>0.0) d = VpGetDoublePosInf();
+ else d = VpGetDoubleNegInf();
}
return rb_float_new(d);
}