summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-31 22:46:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-31 22:46:43 +0000
commit17b0c5c6b535f11de875ba25352057d341d81764 (patch)
tree32c84eace44f2d690db511ec8392172cc22f8191 /ext
parent55483a36f4cae9b3702980b72dae7bc1e39efb7c (diff)
downloadruby-17b0c5c6b535f11de875ba25352057d341d81764.tar.gz
ruby-17b0c5c6b535f11de875ba25352057d341d81764.tar.xz
ruby-17b0c5c6b535f11de875ba25352057d341d81764.zip
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): returns Inf if
exp is bigger than DBL_MANT_DIG. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 2f4b9ada3..bbdab3f2c 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);
}