ruby-changes:44477
From: mrkn <ko1@a...>
Date: Thu, 3 Nov 2016 21:46:27 +0900 (JST)
Subject: [ruby-changes:44477] mrkn:r56550 (trunk): Import from ruby/bigdecimal repository
mrkn 2016-11-03 21:46:22 +0900 (Thu, 03 Nov 2016) New Revision: 56550 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56550 Log: Import from ruby/bigdecimal repository Modified files: trunk/ChangeLog trunk/ext/bigdecimal/bigdecimal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 56549) +++ ChangeLog (revision 56550) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Nov 3 21:45:00 2016 Kenta Murata <mrkn@m...> + + * ext/bigdecimal/bigdecimal.c: Import changes from ruby/bigdecimal + repository. + Thu Nov 3 15:01:29 2016 Nobuyoshi Nakada <nobu@r...> * file.c: include sys/sysmacros.h for ArchLinux which deprecated Index: ext/bigdecimal/bigdecimal.c =================================================================== --- ext/bigdecimal/bigdecimal.c (revision 56549) +++ ext/bigdecimal/bigdecimal.c (revision 56550) @@ -2525,7 +2525,7 @@ BigDecimal_initialize(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2525 /* :nodoc: * - * private method to dup and clone the provided BigDecimal +other+ + * private method for dup and clone the provided BigDecimal +other+ */ static VALUE BigDecimal_initialize_copy(VALUE self, VALUE other) @@ -2760,7 +2760,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALU https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2760 rb_raise(rb_eArgError, "Zero or negative precision for exp"); } - /* TODO: the following switch statement is almostly the same as one in the + /* TODO: the following switch statement is almost same as one in the * BigDecimalCmp function. */ switch (TYPE(x)) { case T_DATA: @@ -2898,7 +2898,7 @@ BigMath_s_log(VALUE klass, VALUE x, VALU https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2898 rb_raise(rb_eArgError, "Zero or negative precision for exp"); } - /* TODO: the following switch statement is almostly the same as one in the + /* TODO: the following switch statement is almost same as one in the * BigDecimalCmp function. */ switch (TYPE(x)) { case T_DATA: @@ -3126,9 +3126,8 @@ get_vp_value: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3126 * * Copyright (C) 2002 by Shigeo Kobayashi <shigeo@t...>. * - * You may distribute under the terms of either the GNU General Public - * License or the Artistic License, as specified in the README file - * of the BigDecimal distribution. + * BigDecimal is released under the Ruby and 2-clause BSD licenses. + * See LICENSE.txt for details. * * Maintained by mrkn <mrkn@m...> and ruby-core members. * @@ -3906,28 +3905,28 @@ VpAlloc(size_t mx, const char *szVal) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3905 if (mx == 0) ++mx; if (szVal) { - while (ISSPACE(*szVal)) szVal++; - if (*szVal != '#') { - if (mf) { - mf = (mf + BASE_FIG - 1) / BASE_FIG + 2; /* Needs 1 more for div */ - if (mx > mf) { - mx = mf; - } - } - } - else { - ++szVal; - } + while (ISSPACE(*szVal)) szVal++; + if (*szVal != '#') { + if (mf) { + mf = (mf + BASE_FIG - 1) / BASE_FIG + 2; /* Needs 1 more for div */ + if (mx > mf) { + mx = mf; + } + } + } + else { + ++szVal; + } } else { - /* necessary to be able to store */ - /* at least mx digits. */ - /* szVal==NULL ==> allocate zero value. */ - vp = VpAllocReal(mx); - /* xmalloc() alway returns(or throw interruption) */ - vp->MaxPrec = mx; /* set max precision */ - VpSetZero(vp, 1); /* initialize vp to zero. */ - return vp; + /* necessary to be able to store */ + /* at least mx digits. */ + /* szVal==NULL ==> allocate zero value. */ + vp = VpAllocReal(mx); + /* xmalloc() alway returns(or throw interruption) */ + vp->MaxPrec = mx; /* set max precision */ + VpSetZero(vp, 1); /* initialize vp to zero. */ + return vp; } /* Skip all '_' after digit: 2006-6-30 */ @@ -3937,43 +3936,42 @@ VpAlloc(size_t mx, const char *szVal) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3936 i = 0; ipn = 0; while ((psz[i] = szVal[ipn]) != 0) { - if (ISDIGIT(psz[i])) ++ni; - if (psz[i] == '_') { - if (ni > 0) { - ipn++; - continue; - } - psz[i] = 0; - break; - } - ++i; - ++ipn; - } - /* Skip trailing spaces */ - while (--i > 0) { - if (ISSPACE(psz[i])) psz[i] = 0; - else break; + if (ISSPACE(psz[i])) { + psz[i] = 0; + break; + } + if (ISDIGIT(psz[i])) ++ni; + if (psz[i] == '_') { + if (ni > 0) { + ipn++; + continue; + } + psz[i] = 0; + break; + } + ++i; + ++ipn; } 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; + 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; + 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; + vp = VpAllocReal(1); + vp->MaxPrec = 1; /* set max precision */ + VpSetNaN(vp); + return vp; } /* check on number szVal[] */ @@ -3983,45 +3981,45 @@ VpAlloc(size_t mx, const char *szVal) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3981 /* Skip digits */ ni = 0; /* digits in mantissa */ while ((v = szVal[i]) != 0) { - if (!ISDIGIT(v)) break; - ++i; - ++ni; + if (!ISDIGIT(v)) break; + ++i; + ++ni; } nf = 0; ipf = 0; ipe = 0; ne = 0; if (v) { - /* other than digit nor \0 */ - if (szVal[i] == '.') { /* xxx. */ - ++i; - ipf = i; - while ((v = szVal[i]) != 0) { /* get fraction part. */ - if (!ISDIGIT(v)) break; - ++i; - ++nf; - } - } - ipe = 0; /* Exponent */ - - switch (szVal[i]) { - case '\0': - break; - case 'e': case 'E': - case 'd': case 'D': - ++i; - ipe = i; - v = szVal[i]; - if ((v == '-') || (v == '+')) ++i; - while ((v=szVal[i]) != 0) { - if (!ISDIGIT(v)) break; - ++i; - ++ne; - } - break; - default: - break; - } + /* other than digit nor \0 */ + if (szVal[i] == '.') { /* xxx. */ + ++i; + ipf = i; + while ((v = szVal[i]) != 0) { /* get fraction part. */ + if (!ISDIGIT(v)) break; + ++i; + ++nf; + } + } + ipe = 0; /* Exponent */ + + switch (szVal[i]) { + case '\0': + break; + case 'e': case 'E': + case 'd': case 'D': + ++i; + ipe = i; + v = szVal[i]; + if ((v == '-') || (v == '+')) ++i; + while ((v=szVal[i]) != 0) { + if (!ISDIGIT(v)) break; + ++i; + ++ne; + } + break; + default: + break; + } } nalloc = (ni + nf + BASE_FIG - 1) / BASE_FIG + 1; /* set effective allocation */ /* units for szVal[] */ @@ -4090,7 +4088,7 @@ VpAsgn(Real *c, Real *a, int isw) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4088 /* * c = a + b when operation = 1 or 2 - * = a - b when operation = -1 or -2. + * c = a - b when operation = -1 or -2. * Returns number of significant digits of c */ VP_EXPORT size_t @@ -4223,7 +4221,7 @@ end_if: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4221 } /* - * Addition of two variable precisional variables + * Addition of two values with variable precision * a and b assuming abs(a)>abs(b). * c = abs(a) + abs(b) ; where |a|>=|b| */ @@ -4982,7 +4980,7 @@ VpComp(Real *a, Real *b) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4980 goto Exit; } - /* a and b have same exponent, then compare significand. */ + /* a and b have same exponent, then compare their significand. */ mx = (a->Prec < b->Prec) ? a->Prec : b->Prec; ind = 0; while (ind < mx) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/