From 2308fb170e5a1d1f6ad580fe3620d24d75069585 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 5 Dec 2013 16:34:59 +0000 Subject: * ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): treat 0.0 and -0.0 of floating-point numbers specially for an optimization and to correctly propagate its signbit to the result. [Bug #9214] [ruby-core:58858] * test/bigdecimal/test_bigdecimal.rb: add tests case for the above change. * test/bigdecimal/test_bigdecimal_util.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 29240c7da4..e0cd4b006b 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -199,14 +199,23 @@ GetVpValueWithPrec(VALUE v, long prec, int must) VALUE num, bg; char szD[128]; VALUE orig = Qundef; + double d; again: switch(TYPE(v)) { case T_FLOAT: if (prec < 0) goto unable_to_coerce_without_prec; if (prec > DBL_DIG+1) goto SomeOneMayDoIt; - v = rb_funcall(v, id_to_r, 0); - goto again; + d = RFLOAT_VALUE(v); + if (d != 0.0) { + v = rb_funcall(v, id_to_r, 0); + goto again; + } + if (1/d < 0.0) { + return VpCreateRbObject(prec, "-0"); + } + return VpCreateRbObject(prec, "0"); + case T_RATIONAL: if (prec < 0) goto unable_to_coerce_without_prec; -- cgit v1.2.3