From 42a677c895f82bcd611db2773fbe68b0558b142d Mon Sep 17 00:00:00 2001 From: mrkn Date: Sat, 10 Dec 2016 08:56:05 +0000 Subject: [PATCH] bigdecimal: version 1.3.0.pre.2 Import bigdecimal version 1.3.0.pre.2. The full commit log is here: https://github.com/ruby/bigdecimal/compare/v1.3.0.pre...v1.3.0.pre.2 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 40 +++++++++++++++--------------- ext/bigdecimal/bigdecimal.gemspec | 2 +- test/bigdecimal/test_bigdecimal.rb | 9 +++++++ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index dd8f0f9d85..34817304e8 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -4003,26 +4003,6 @@ VpAlloc(size_t mx, const char *szVal) return vp; } - /* Check on Inf & NaN */ - if (StrCmp(szVal, SZ_PINF) == 0 || StrCmp(szVal, SZ_INF) == 0 ) { - vp = VpAllocReal(1); - vp->MaxPrec = 1; /* set max precision */ - VpSetPosInf(vp); - return vp; - } - if (StrCmp(szVal, SZ_NINF) == 0) { - vp = VpAllocReal(1); - vp->MaxPrec = 1; /* set max precision */ - VpSetNegInf(vp); - return vp; - } - if (StrCmp(szVal, SZ_NaN) == 0) { - vp = VpAllocReal(1); - vp->MaxPrec = 1; /* set max precision */ - VpSetNaN(vp); - return vp; - } - /* Skip all '_' after digit: 2006-6-30 */ ni = 0; buf = rb_str_tmp_new(strlen(szVal) + 1); @@ -4048,6 +4028,26 @@ VpAlloc(size_t mx, const char *szVal) } szVal = psz; + /* Check on Inf & NaN */ + if (StrCmp(szVal, SZ_PINF) == 0 || StrCmp(szVal, SZ_INF) == 0 ) { + vp = VpAllocReal(1); + vp->MaxPrec = 1; /* set max precision */ + VpSetPosInf(vp); + return vp; + } + if (StrCmp(szVal, SZ_NINF) == 0) { + vp = VpAllocReal(1); + vp->MaxPrec = 1; /* set max precision */ + VpSetNegInf(vp); + return vp; + } + if (StrCmp(szVal, SZ_NaN) == 0) { + vp = VpAllocReal(1); + vp->MaxPrec = 1; /* set max precision */ + VpSetNaN(vp); + return vp; + } + /* check on number szVal[] */ ipn = i = 0; if (szVal[i] == '-') { sign=-1; ++i; } diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec index 98e0125904..e01649f2fe 100644 --- a/ext/bigdecimal/bigdecimal.gemspec +++ b/ext/bigdecimal/bigdecimal.gemspec @@ -1,5 +1,5 @@ # coding: utf-8 -_VERSION = '1.3.0.pre' +_VERSION = '1.3.0.pre.2' Gem::Specification.new do |s| s.name = "bigdecimal" diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index dd22997efd..45a65d8164 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -53,6 +53,15 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(1, BigDecimal("1")) assert_equal(1, BigDecimal("1", 1)) assert_raise(ArgumentError) { BigDecimal("1", -1) } + + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false) + BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) + assert_equal(1234, BigDecimal(" \t\n\r \r1234 \t\n\r \r")) + assert_positive_infinite(BigDecimal(" \t\n\r \rInfinity \t\n\r \r")) + assert_negative_infinite(BigDecimal(" \t\n\r \r-Infinity \t\n\r \r")) + assert_nan(BigDecimal(" \t\n\r \rNaN \t\n\r \r")) + end end def test_global_new_with_invalid_string