From 5594f2bffbc488d9f8d6daa83fe60c68038eecc3 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 31 May 2009 22:46:43 +0000 Subject: * 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/trunk@23609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 2f4b9ada34..bbdab3f2c8 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -604,16 +604,18 @@ BigDecimal_to_f(VALUE self) volatile VALUE str; GUARD_OBJ(p,GetVpValue(self,1)); - if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d); + if (VpVtoD(&d, &e, p)!=1) return rb_float_new(d); + if (e > DBL_MAX_10_EXP) goto erange; str = rb_str_new(0, VpNumOfChars(p,"E")); buf = RSTRING_PTR(str); 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); } -- cgit v1.2.3