* ext/bigdecimal/bigdecimal.c: Fix style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c60c050378
commit
e52a4a70a9
@ -1,3 +1,7 @@
|
||||
Fri Mar 22 10:29:00 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/bigdecimal/bigdecimal.c: Fix style.
|
||||
|
||||
Fri Mar 22 05:30:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (ambiguous_operator): refine warning message, since this
|
||||
|
@ -163,9 +163,11 @@ ToValue(Real *p)
|
||||
{
|
||||
if (VpIsNaN(p)) {
|
||||
VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 0);
|
||||
} else if(VpIsPosInf(p)) {
|
||||
}
|
||||
else if (VpIsPosInf(p)) {
|
||||
VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 0);
|
||||
} else if(VpIsNegInf(p)) {
|
||||
}
|
||||
else if (VpIsNegInf(p)) {
|
||||
VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 0);
|
||||
}
|
||||
return p->obj;
|
||||
@ -200,8 +202,7 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||
VALUE orig = Qundef;
|
||||
|
||||
again:
|
||||
switch(TYPE(v))
|
||||
{
|
||||
switch(TYPE(v)) {
|
||||
case T_FLOAT:
|
||||
if (prec < 0) goto unable_to_coerce_without_prec;
|
||||
if (prec > DBL_DIG+1) goto SomeOneMayDoIt;
|
||||
@ -389,7 +390,9 @@ BigDecimal_load(VALUE self, VALUE str)
|
||||
if (m > VpBaseFig()) m -= VpBaseFig();
|
||||
GUARD_OBJ(pv, VpNewRbClass(m, (char *)pch, self));
|
||||
m /= VpBaseFig();
|
||||
if(m && pv->MaxPrec>m) pv->MaxPrec = m+1;
|
||||
if (m && pv->MaxPrec > m) {
|
||||
pv->MaxPrec = m+1;
|
||||
}
|
||||
return ToValue(pv);
|
||||
}
|
||||
|
||||
@ -474,8 +477,7 @@ BigDecimal_mode(int argc, VALUE *argv, VALUE self)
|
||||
VALUE val;
|
||||
unsigned long f,fo;
|
||||
|
||||
if(rb_scan_args(argc,argv,"11",&which,&val)==1) val = Qnil;
|
||||
|
||||
rb_scan_args(argc, argv, "11", &which, &val);
|
||||
Check_Type(which, T_FIXNUM);
|
||||
f = (unsigned long)FIX2INT(which);
|
||||
|
||||
@ -626,9 +628,11 @@ BigDecimal_check_num(Real *p)
|
||||
{
|
||||
if (VpIsNaN(p)) {
|
||||
VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 1);
|
||||
} else if(VpIsPosInf(p)) {
|
||||
}
|
||||
else if (VpIsPosInf(p)) {
|
||||
VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 1);
|
||||
} else if(VpIsNegInf(p)) {
|
||||
}
|
||||
else if (VpIsNegInf(p)) {
|
||||
VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 1);
|
||||
}
|
||||
}
|
||||
@ -670,12 +674,14 @@ BigDecimal_to_i(VALUE self)
|
||||
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
|
||||
INT2FIX(-dpower)));
|
||||
}
|
||||
else
|
||||
else {
|
||||
ret = rb_funcall(numerator, '*', 1,
|
||||
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
|
||||
INT2FIX(dpower)));
|
||||
if (RB_TYPE_P(ret, T_FLOAT))
|
||||
}
|
||||
if (RB_TYPE_P(ret, T_FLOAT)) {
|
||||
rb_raise(rb_eFloatDomainError, "Infinity");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -914,11 +920,13 @@ BigDecimal_sub(VALUE self, VALUE r)
|
||||
if (mx == (size_t)-1L) {
|
||||
GUARD_OBJ(c,VpCreateRbObject(VpBaseFig() + 1, "0"));
|
||||
VpAddSub(c, a, b, -1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
GUARD_OBJ(c,VpCreateRbObject(mx *(VpBaseFig() + 1), "0"));
|
||||
if (!mx) {
|
||||
VpSetInf(c,VpGetSign(a));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpAddSub(c, a, b, -1);
|
||||
}
|
||||
}
|
||||
@ -1464,7 +1472,7 @@ BigDecimal_div2(int argc, VALUE *argv, VALUE self)
|
||||
else {
|
||||
Real *res = NULL;
|
||||
Real *av = NULL, *bv = NULL, *cv = NULL;
|
||||
size_t mx = (ix+VpBaseFig()*2);
|
||||
size_t mx = ix + VpBaseFig()*2;
|
||||
size_t pl = VpSetPrecLimit(0);
|
||||
|
||||
GUARD_OBJ(cv, VpCreateRbObject(mx, "0"));
|
||||
@ -1638,6 +1646,8 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
|
||||
iLoc = FIX2INT(vLoc);
|
||||
sw = check_rounding_mode(vRound);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pl = VpSetPrecLimit(0);
|
||||
@ -1680,7 +1690,8 @@ BigDecimal_truncate(int argc, VALUE *argv, VALUE self)
|
||||
|
||||
if (rb_scan_args(argc, argv, "01", &vLoc) == 0) {
|
||||
iLoc = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Check_Type(vLoc, T_FIXNUM);
|
||||
iLoc = FIX2INT(vLoc);
|
||||
}
|
||||
@ -1740,7 +1751,8 @@ BigDecimal_floor(int argc, VALUE *argv, VALUE self)
|
||||
|
||||
if (rb_scan_args(argc, argv, "01", &vLoc)==0) {
|
||||
iLoc = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Check_Type(vLoc, T_FIXNUM);
|
||||
iLoc = FIX2INT(vLoc);
|
||||
}
|
||||
@ -2494,7 +2506,7 @@ BigDecimal_limit(int argc, VALUE *argv, VALUE self)
|
||||
|
||||
if (rb_scan_args(argc, argv, "01", &nFig) == 1) {
|
||||
int nf;
|
||||
if(nFig==Qnil) return nCur;
|
||||
if (NIL_P(nFig)) return nCur;
|
||||
Check_Type(nFig, T_FIXNUM);
|
||||
nf = FIX2INT(nFig);
|
||||
if (nf < 0) {
|
||||
@ -3520,11 +3532,8 @@ VpException(unsigned short f, const char *str,int always)
|
||||
if (f == VP_EXCEPTION_OP || f == VP_EXCEPTION_MEMORY) always = 1;
|
||||
|
||||
if (always || (exception_mode & f)) {
|
||||
switch(f)
|
||||
{
|
||||
/*
|
||||
case VP_EXCEPTION_OVERFLOW:
|
||||
*/
|
||||
switch(f) {
|
||||
/* case VP_EXCEPTION_OVERFLOW: */
|
||||
case VP_EXCEPTION_ZERODIVIDE:
|
||||
case VP_EXCEPTION_INFINITY:
|
||||
case VP_EXCEPTION_NaN:
|
||||
@ -3561,13 +3570,13 @@ VpIsDefOP(Real *c,Real *a,Real *b,int sw)
|
||||
|
||||
if (VpIsInf(a)) {
|
||||
if (VpIsInf(b)) {
|
||||
switch(sw)
|
||||
{
|
||||
switch(sw) {
|
||||
case 1: /* + */
|
||||
if (VpGetSign(a) == VpGetSign(b)) {
|
||||
VpSetInf(c, VpGetSign(a));
|
||||
goto Inf;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpSetNaN(c);
|
||||
goto NaN;
|
||||
}
|
||||
@ -3575,7 +3584,8 @@ VpIsDefOP(Real *c,Real *a,Real *b,int sw)
|
||||
if (VpGetSign(a) != VpGetSign(b)) {
|
||||
VpSetInf(c, VpGetSign(a));
|
||||
goto Inf;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpSetNaN(c);
|
||||
goto NaN;
|
||||
}
|
||||
@ -3592,8 +3602,7 @@ VpIsDefOP(Real *c,Real *a,Real *b,int sw)
|
||||
goto NaN;
|
||||
}
|
||||
/* Inf op Finite */
|
||||
switch(sw)
|
||||
{
|
||||
switch(sw) {
|
||||
case 1: /* + */
|
||||
case 2: /* - */
|
||||
VpSetInf(c, VpGetSign(a));
|
||||
@ -3612,8 +3621,7 @@ VpIsDefOP(Real *c,Real *a,Real *b,int sw)
|
||||
}
|
||||
|
||||
if (VpIsInf(b)) {
|
||||
switch(sw)
|
||||
{
|
||||
switch(sw) {
|
||||
case 1: /* + */
|
||||
VpSetInf(c, VpGetSign(b));
|
||||
break;
|
||||
@ -3656,8 +3664,7 @@ VpNumOfChars(Real *vp,const char *pszFmt)
|
||||
if (vp == NULL) return BASE_FIG*2+6;
|
||||
if (!VpIsDef(vp)) return 32; /* not sure,may be OK */
|
||||
|
||||
switch(*pszFmt)
|
||||
{
|
||||
switch(*pszFmt) {
|
||||
case 'F':
|
||||
nc = BASE_FIG*(vp->Prec + 1)+2;
|
||||
ex = vp->exponent;
|
||||
@ -3671,6 +3678,7 @@ VpNumOfChars(Real *vp,const char *pszFmt)
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
/* fall through */
|
||||
default:
|
||||
nc = BASE_FIG*(vp->Prec + 2)+6; /* 3: sign + exponent chars */
|
||||
}
|
||||
@ -3741,7 +3749,8 @@ AddExponent(Real *a, SIGNED_VALUE n)
|
||||
eb = e*(SIGNED_VALUE)BASE_FIG;
|
||||
if (mb < eb) goto overflow;
|
||||
}
|
||||
} else if(n<0) {
|
||||
}
|
||||
else if (n < 0) {
|
||||
mb = m*(SIGNED_VALUE)BASE_FIG;
|
||||
eb = e*(SIGNED_VALUE)BASE_FIG;
|
||||
if (mb > eb) goto underflow;
|
||||
@ -3817,7 +3826,10 @@ VpAlloc(size_t mx, const char *szVal)
|
||||
while ((psz[i] = szVal[ipn]) != 0) {
|
||||
if (ISDIGIT(psz[i])) ++ni;
|
||||
if (psz[i] == '_') {
|
||||
if (ni > 0) { ipn++; continue; }
|
||||
if (ni > 0) {
|
||||
ipn++;
|
||||
continue;
|
||||
}
|
||||
psz[i] = 0;
|
||||
break;
|
||||
}
|
||||
@ -3832,8 +3844,7 @@ VpAlloc(size_t mx, const char *szVal)
|
||||
szVal = psz;
|
||||
|
||||
/* Check on Inf & NaN */
|
||||
if (StrCmp(szVal, SZ_PINF) == 0 ||
|
||||
StrCmp(szVal, SZ_INF) == 0 ) {
|
||||
if (StrCmp(szVal, SZ_PINF) == 0 || StrCmp(szVal, SZ_INF) == 0 ) {
|
||||
vp = VpAllocReal(1);
|
||||
vp->MaxPrec = 1; /* set max precision */
|
||||
VpSetPosInf(vp);
|
||||
@ -3941,7 +3952,7 @@ VpAsgn(Real *c, Real *a, int isw)
|
||||
/* check if the RHS is zero */
|
||||
if (!VpIsZero(a)) {
|
||||
c->exponent = a->exponent; /* store exponent */
|
||||
VpSetSign(c,(isw*VpGetSign(a))); /* set sign */
|
||||
VpSetSign(c, isw * VpGetSign(a)); /* set sign */
|
||||
n = (a->Prec < c->MaxPrec) ? (a->Prec) : (c->MaxPrec);
|
||||
c->Prec = n;
|
||||
memcpy(c->frac, a->frac, n * sizeof(BDIGIT));
|
||||
@ -3950,11 +3961,13 @@ VpAsgn(Real *c, Real *a, int isw)
|
||||
/* Not in ActiveRound */
|
||||
if(c->Prec < a->Prec) {
|
||||
VpInternalRound(c, n, (n>0) ? a->frac[n-1] : 0, a->frac[n]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpLimitRound(c,0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* The value of 'a' is zero. */
|
||||
VpSetZero(c, isw * VpGetSign(a));
|
||||
return 1;
|
||||
@ -3990,12 +4003,14 @@ VpAddSub(Real *c, Real *a, Real *b, int operation)
|
||||
/* a is zero,then assign b to c */
|
||||
if (!VpIsZero(b)) {
|
||||
VpAsgn(c, b, operation);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* Both a and b are zero. */
|
||||
if (VpGetSign(a) < 0 && operation * VpGetSign(b) < 0) {
|
||||
/* -0 -0 */
|
||||
VpSetZero(c, -1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpSetZero(c, 1);
|
||||
}
|
||||
return 1; /* 0: 1 significant digits */
|
||||
@ -4031,7 +4046,8 @@ VpAddSub(Real *c, Real *a, Real *b, int operation)
|
||||
a_ptr = a;
|
||||
b_ptr = b;
|
||||
goto end_if;
|
||||
} else if(a->frac[i] < b->frac[i]) {
|
||||
}
|
||||
else if (a->frac[i] < b->frac[i]) {
|
||||
a_ptr = b;
|
||||
b_ptr = a;
|
||||
goto end_if;
|
||||
@ -4041,7 +4057,8 @@ VpAddSub(Real *c, Real *a, Real *b, int operation)
|
||||
a_ptr = a;
|
||||
b_ptr = b;
|
||||
goto end_if;
|
||||
} else if(na < nb) {
|
||||
}
|
||||
else if (na < nb) {
|
||||
a_ptr = b;
|
||||
b_ptr = a;
|
||||
goto end_if;
|
||||
@ -4068,12 +4085,14 @@ end_if:
|
||||
VpSetSign(c, 1);
|
||||
mrv = VpAddAbs(a_ptr, b_ptr, c);
|
||||
VpSetSign(c, isw / 2);
|
||||
} else { /* subtraction */
|
||||
}
|
||||
else { /* subtraction */
|
||||
VpSetSign(c, 1);
|
||||
mrv = VpSubAbs(a_ptr, b_ptr, c);
|
||||
if (a_ptr == a) {
|
||||
VpSetSign(c,VpGetSign(a));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpSetSign(c, VpGetSign(a_ptr) * sw);
|
||||
}
|
||||
}
|
||||
@ -4129,7 +4148,8 @@ VpAddAbs(Real *a, Real *b, Real *c)
|
||||
--c_pos;
|
||||
if (b_pos > 0) {
|
||||
c->frac[c_pos] = b->frac[--b_pos];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
--word_shift;
|
||||
c->frac[c_pos] = 0;
|
||||
}
|
||||
@ -4150,7 +4170,8 @@ VpAddAbs(Real *a, Real *b, Real *c)
|
||||
if (c->frac[c_pos] >= BASE) {
|
||||
c->frac[c_pos] -= BASE;
|
||||
carry = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
carry = 0;
|
||||
}
|
||||
}
|
||||
@ -4162,7 +4183,8 @@ VpAddAbs(Real *a, Real *b, Real *c)
|
||||
if (c->frac[c_pos] >= BASE) {
|
||||
c->frac[c_pos] -= BASE;
|
||||
carry = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
carry = 0;
|
||||
}
|
||||
}
|
||||
@ -4215,7 +4237,8 @@ VpSubAbs(Real *a, Real *b, Real *c)
|
||||
if (av >= bv) {
|
||||
mrv = av - bv;
|
||||
borrow = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mrv = 0;
|
||||
borrow = 1;
|
||||
}
|
||||
@ -4228,7 +4251,8 @@ VpSubAbs(Real *a, Real *b, Real *c)
|
||||
--c_pos;
|
||||
if (b_pos > 0) {
|
||||
c->frac[c_pos] = BASE - b->frac[--b_pos] - borrow;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
--word_shift;
|
||||
c->frac[c_pos] = BASE - borrow;
|
||||
}
|
||||
@ -4250,7 +4274,8 @@ VpSubAbs(Real *a, Real *b, Real *c)
|
||||
if (a->frac[--a_pos] < b->frac[--b_pos] + borrow) {
|
||||
c->frac[c_pos] = BASE + a->frac[a_pos] - b->frac[b_pos] - borrow;
|
||||
borrow = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
c->frac[c_pos] = a->frac[a_pos] - b->frac[b_pos] - borrow;
|
||||
borrow = 0;
|
||||
}
|
||||
@ -4263,7 +4288,8 @@ VpSubAbs(Real *a, Real *b, Real *c)
|
||||
if (a->frac[--a_pos] < borrow) {
|
||||
c->frac[c_pos] = BASE + a->frac[a_pos] - borrow;
|
||||
borrow = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
c->frac[c_pos] = a->frac[a_pos] - borrow;
|
||||
borrow = 0;
|
||||
}
|
||||
@ -4304,10 +4330,10 @@ VpSetPTR(Real *a, Real *b, Real *c, size_t *a_pos, size_t *b_pos, size_t *c_pos,
|
||||
size_t left_word, right_word, word_shift;
|
||||
c->frac[0] = 0;
|
||||
*av = *bv = 0;
|
||||
word_shift =((a->exponent) -(b->exponent));
|
||||
word_shift = (a->exponent - b->exponent);
|
||||
left_word = b->Prec + word_shift;
|
||||
right_word = Max((a->Prec),left_word);
|
||||
left_word =(c->MaxPrec) - 1; /* -1 ... prepare for round up */
|
||||
right_word = Max(a->Prec, left_word);
|
||||
left_word = c->MaxPrec - 1; /* -1 ... prepare for round up */
|
||||
/*
|
||||
* check if 'round' is needed.
|
||||
*/
|
||||
@ -4323,7 +4349,7 @@ VpSetPTR(Real *a, Real *b, Real *c, size_t *a_pos, size_t *b_pos, size_t *c_pos,
|
||||
*/
|
||||
*c_pos = right_word = left_word + 1; /* Set resulting precision */
|
||||
/* be equal to that of c */
|
||||
if((a->Prec) >=(c->MaxPrec)) {
|
||||
if (a->Prec >= c->MaxPrec) {
|
||||
/*
|
||||
* a = xxxxxxAxxx
|
||||
* c = xxxxxx
|
||||
@ -4331,7 +4357,8 @@ VpSetPTR(Real *a, Real *b, Real *c, size_t *a_pos, size_t *b_pos, size_t *c_pos,
|
||||
*/
|
||||
*a_pos = left_word;
|
||||
*av = a->frac[*a_pos]; /* av is 'A' shown in above. */
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* a = xxxxxxx
|
||||
* c = xxxxxxxxxx
|
||||
@ -4339,20 +4366,22 @@ VpSetPTR(Real *a, Real *b, Real *c, size_t *a_pos, size_t *b_pos, size_t *c_pos,
|
||||
*/
|
||||
*a_pos = a->Prec;
|
||||
}
|
||||
if((b->Prec + word_shift) >= c->MaxPrec) {
|
||||
if (b->Prec + word_shift >= c->MaxPrec) {
|
||||
/*
|
||||
* a = xxxxxxxxx
|
||||
* b = xxxxxxxBxxx
|
||||
* c = xxxxxxxxxxx
|
||||
* b_pos = |
|
||||
*/
|
||||
if(c->MaxPrec >=(word_shift + 1)) {
|
||||
if (c->MaxPrec >= word_shift + 1) {
|
||||
*b_pos = c->MaxPrec - word_shift - 1;
|
||||
*bv = b->frac[*b_pos];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
*b_pos = -1L;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* a = xxxxxxxxxxxxxxxx
|
||||
* b = xxxxxx
|
||||
@ -4361,7 +4390,8 @@ VpSetPTR(Real *a, Real *b, Real *c, size_t *a_pos, size_t *b_pos, size_t *c_pos,
|
||||
*/
|
||||
*b_pos = b->Prec;
|
||||
}
|
||||
} else { /* The MaxPrec of c - 1 > The Prec of a + b */
|
||||
}
|
||||
else { /* The MaxPrec of c - 1 > The Prec of a + b */
|
||||
/*
|
||||
* a = xxxxxxx
|
||||
* b = xxxxxx
|
||||
@ -4426,7 +4456,7 @@ VpMult(Real *c, Real *a, Real *b)
|
||||
VpAsgn(c, a, VpGetSign(b));
|
||||
goto Exit;
|
||||
}
|
||||
if((b->Prec) >(a->Prec)) {
|
||||
if (b->Prec > a->Prec) {
|
||||
/* Adjust so that digits(a)>digits(b) */
|
||||
w = a;
|
||||
a = b;
|
||||
@ -4461,11 +4491,13 @@ VpMult(Real *c, Real *a, Real *b)
|
||||
ind_as = MxIndA - nc;
|
||||
ind_ae = MxIndA;
|
||||
ind_bs = MxIndB;
|
||||
} else if(nc <= MxIndA) { /* The middle rectangular of the Fig. */
|
||||
}
|
||||
else if (nc <= MxIndA) { /* The middle rectangular of the Fig. */
|
||||
ind_as = MxIndA - nc;
|
||||
ind_ae = MxIndA - (nc - MxIndB);
|
||||
ind_bs = MxIndB;
|
||||
} else if(nc > MxIndA) { /* The right triangle of the Fig. */
|
||||
}
|
||||
else if (nc > MxIndA) { /* The right triangle of the Fig. */
|
||||
ind_as = 0;
|
||||
ind_ae = MxIndAB - nc - 1;
|
||||
ind_bs = MxIndB - (nc - MxIndA);
|
||||
@ -4488,7 +4520,8 @@ VpMult(Real *c, Real *a, Real *b)
|
||||
if (c->frac[ii] >= BASE) {
|
||||
carry = c->frac[ii] / BASE;
|
||||
c->frac[ii] -= (carry * BASE);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -4500,7 +4533,8 @@ VpMult(Real *c, Real *a, Real *b)
|
||||
VpAsgn(w, c, 1);
|
||||
VpFree(c);
|
||||
c = w;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpLimitRound(c,0);
|
||||
}
|
||||
|
||||
@ -4581,7 +4615,8 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
|
||||
b1 = b1p1 = b->frac[0];
|
||||
if (b->Prec <= 1) {
|
||||
b1b2p1 = b1b2 = b1p1 * BASE;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
b1p1 = b1 + 1;
|
||||
b1b2p1 = b1b2 = b1 * BASE + b->frac[1];
|
||||
if (b->Prec > 2) ++b1b2p1;
|
||||
@ -4620,7 +4655,8 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
|
||||
if (r->frac[ind_r] < b->frac[ind_b] + borrow) {
|
||||
r->frac[ind_r] += (BASE - (b->frac[ind_b] + borrow));
|
||||
borrow = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
r->frac[ind_r] = r->frac[ind_r] - b->frac[ind_b] - borrow;
|
||||
borrow = 0;
|
||||
}
|
||||
@ -4661,7 +4697,8 @@ sub_mult:
|
||||
if(r->frac[ind_r] < qb) {
|
||||
r->frac[ind_r] += (BDIGIT)(BASE - qb);
|
||||
borrow2 = borrow2 + borrow1 + 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
r->frac[ind_r] -= (BDIGIT)qb;
|
||||
borrow2 += borrow1;
|
||||
}
|
||||
@ -4669,7 +4706,8 @@ sub_mult:
|
||||
if(r->frac[ind_r - 1] < borrow2) {
|
||||
r->frac[ind_r - 1] += (BASE - borrow2);
|
||||
borrow2 = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
r->frac[ind_r - 1] -= borrow2;
|
||||
borrow2 = 0;
|
||||
}
|
||||
@ -4778,6 +4816,7 @@ VpComp(Real *a, Real *b)
|
||||
if (!VpIsDef(a)) {
|
||||
if (!VpIsDef(b)) e = a->sign - b->sign;
|
||||
else e = a->sign;
|
||||
|
||||
if (e > 0) return 1;
|
||||
else if (e < 0) return -1;
|
||||
else return 0;
|
||||
@ -4809,32 +4848,33 @@ VpComp(Real *a, Real *b)
|
||||
}
|
||||
|
||||
/* a and b have same sign, && signe!=0,then compare exponent */
|
||||
if((a->exponent) >(b->exponent)) {
|
||||
if (a->exponent > b->exponent) {
|
||||
val = VpGetSign(a);
|
||||
goto Exit;
|
||||
}
|
||||
if((a->exponent) <(b->exponent)) {
|
||||
if (a->exponent < b->exponent) {
|
||||
val = -VpGetSign(b);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* a and b have same exponent, then compare significand. */
|
||||
mx =((a->Prec) <(b->Prec)) ?(a->Prec) :(b->Prec);
|
||||
mx = (a->Prec < b->Prec) ? a->Prec : b->Prec;
|
||||
ind = 0;
|
||||
while (ind < mx) {
|
||||
if((a->frac[ind]) >(b->frac[ind])) {
|
||||
if (a->frac[ind] > b->frac[ind]) {
|
||||
val = VpGetSign(a);
|
||||
goto Exit;
|
||||
}
|
||||
if((a->frac[ind]) <(b->frac[ind])) {
|
||||
if (a->frac[ind] < b->frac[ind]) {
|
||||
val = -VpGetSign(b);
|
||||
goto Exit;
|
||||
}
|
||||
++ind;
|
||||
}
|
||||
if((a->Prec) >(b->Prec)) {
|
||||
if (a->Prec > b->Prec) {
|
||||
val = VpGetSign(a);
|
||||
} else if((a->Prec) <(b->Prec)) {
|
||||
}
|
||||
else if (a->Prec < b->Prec) {
|
||||
val = -VpGetSign(b);
|
||||
}
|
||||
|
||||
@ -4893,7 +4933,7 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
||||
/* nc : number of caracters printed */
|
||||
ZeroSup = 1; /* Flag not to print the leading zeros as 0.00xxxxEnn */
|
||||
while (*(cntl_chr + j)) {
|
||||
if((*(cntl_chr + j) == '%') &&(*(cntl_chr + j + 1) != '%')) {
|
||||
if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') {
|
||||
nc = 0;
|
||||
if (!VpIsZero(a)) {
|
||||
if (VpGetSign(a) < 0) {
|
||||
@ -4906,7 +4946,7 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
||||
e = a->frac[i];
|
||||
while (m) {
|
||||
nn = e / m;
|
||||
if((!ZeroSup) || nn) {
|
||||
if (!ZeroSup || nn) {
|
||||
nc += fprintf(fp, "%lu", (unsigned long)nn); /* The leading zero(s) */
|
||||
/* as 0.00xx will not */
|
||||
/* be printed. */
|
||||
@ -4922,10 +4962,12 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
||||
}
|
||||
}
|
||||
nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
nc += fprintf(fp, "0.0");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
++nc;
|
||||
if (*(cntl_chr + j) == '\\') {
|
||||
switch (*(cntl_chr + j + 1)) {
|
||||
@ -4945,7 +4987,8 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
||||
fprintf(fp, "%c", *(cntl_chr + j));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fprintf(fp, "%c", *(cntl_chr + j));
|
||||
if (*(cntl_chr + j) == '%') ++j;
|
||||
}
|
||||
@ -4971,8 +5014,8 @@ VpFormatSt(char *psz, size_t fFmt)
|
||||
if (ISSPACE(ch) || ch=='-' || ch=='+') continue;
|
||||
if (ch == '.') { nf = 0; continue; }
|
||||
if (ch == 'E') break;
|
||||
nf++;
|
||||
if(nf > fFmt) {
|
||||
|
||||
if (++nf > fFmt) {
|
||||
memmove(psz + i + 1, psz + i, ie - i + 1);
|
||||
++ie;
|
||||
nf = 0;
|
||||
@ -5026,7 +5069,7 @@ VpSzMantissa(Real *a,char *psz)
|
||||
e = a->frac[i];
|
||||
while (m) {
|
||||
nn = e / m;
|
||||
if((!ZeroSup) || nn) {
|
||||
if (!ZeroSup || nn) {
|
||||
sprintf(psz, "%lu", (unsigned long)nn); /* The leading zero(s) */
|
||||
psz += strlen(psz);
|
||||
/* as 0.00xx will be ignored. */
|
||||
@ -5038,7 +5081,8 @@ VpSzMantissa(Real *a,char *psz)
|
||||
}
|
||||
*psz = 0;
|
||||
while (psz[-1] == '0') *(--psz) = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (VpIsPosZero(a)) sprintf(psz, "0");
|
||||
else sprintf(psz, "-0");
|
||||
}
|
||||
@ -5056,7 +5100,8 @@ VpToSpecialString(Real *a,char *psz,int fPlus)
|
||||
if (VpIsPosInf(a)) {
|
||||
if (fPlus == 1) {
|
||||
*psz++ = ' ';
|
||||
} else if(fPlus==2) {
|
||||
}
|
||||
else if (fPlus == 2) {
|
||||
*psz++ = '+';
|
||||
}
|
||||
sprintf(psz, SZ_INF);
|
||||
@ -5071,7 +5116,8 @@ VpToSpecialString(Real *a,char *psz,int fPlus)
|
||||
if (fPlus == 1) sprintf(psz, " 0.0");
|
||||
else if (fPlus == 2) sprintf(psz, "+0.0");
|
||||
else sprintf(psz, "0.0");
|
||||
} else sprintf(psz, "-0.0");
|
||||
}
|
||||
else sprintf(psz, "-0.0");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -5102,7 +5148,7 @@ VpToString(Real *a, char *psz, size_t fFmt, int fPlus)
|
||||
e = a->frac[i];
|
||||
while (m) {
|
||||
nn = e / m;
|
||||
if((!ZeroSup) || nn) {
|
||||
if (!ZeroSup || nn) {
|
||||
sprintf(psz, "%lu", (unsigned long)nn); /* The reading zero(s) */
|
||||
psz += strlen(psz);
|
||||
/* as 0.00xx will be ignored. */
|
||||
@ -5118,7 +5164,9 @@ VpToString(Real *a, char *psz, size_t fFmt, int fPlus)
|
||||
--ex;
|
||||
shift /= 10;
|
||||
}
|
||||
while(psz[-1]=='0') *(--psz) = 0;
|
||||
while (psz[-1] == '0') {
|
||||
*(--psz) = 0;
|
||||
}
|
||||
sprintf(psz, "E%"PRIdSIZE, ex);
|
||||
if (fFmt) VpFormatSt(pszSav, fFmt);
|
||||
}
|
||||
@ -5154,7 +5202,8 @@ VpToFString(Real *a, char *psz, size_t fFmt, int fPlus)
|
||||
if (i == 0 && ex >= 0) {
|
||||
sprintf(psz, "%lu", (unsigned long)a->frac[i]);
|
||||
psz += strlen(psz);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
m = BASE1;
|
||||
e = a->frac[i];
|
||||
while (m) {
|
||||
@ -5234,7 +5283,8 @@ VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, con
|
||||
sign = -1;
|
||||
++i;
|
||||
++mi;
|
||||
} else if(int_chr[0] == '+') {
|
||||
}
|
||||
else if (int_chr[0] == '+') {
|
||||
++i;
|
||||
++mi;
|
||||
}
|
||||
@ -5277,7 +5327,7 @@ VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, con
|
||||
ind_a = 0;
|
||||
while (i < mi) {
|
||||
a->frac[ind_a] = 0;
|
||||
while ((j < BASE_FIG) && (i < mi)) {
|
||||
while (j < BASE_FIG && i < mi) {
|
||||
a->frac[ind_a] = a->frac[ind_a] * 10 + int_chr[i] - '0';
|
||||
++j;
|
||||
++i;
|
||||
@ -5293,7 +5343,7 @@ VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, con
|
||||
|
||||
i = 0;
|
||||
while (i < nf) {
|
||||
while((j < BASE_FIG) && (i < nf)) {
|
||||
while (j < BASE_FIG && i < nf) {
|
||||
a->frac[ind_a] = a->frac[ind_a] * 10 + frac[i] - '0';
|
||||
++j;
|
||||
++i;
|
||||
@ -5349,26 +5399,26 @@ VpVtoD(double *d, SIGNED_VALUE *e, Real *m)
|
||||
*e = 0;
|
||||
f = -1; /* NaN */
|
||||
goto Exit;
|
||||
} else
|
||||
if(VpIsPosZero(m)) {
|
||||
}
|
||||
else if (VpIsPosZero(m)) {
|
||||
*d = 0.0;
|
||||
*e = 0;
|
||||
f = 0;
|
||||
goto Exit;
|
||||
} else
|
||||
if(VpIsNegZero(m)) {
|
||||
}
|
||||
else if (VpIsNegZero(m)) {
|
||||
*d = VpGetDoubleNegZero();
|
||||
*e = 0;
|
||||
f = 0;
|
||||
goto Exit;
|
||||
} else
|
||||
if(VpIsPosInf(m)) {
|
||||
}
|
||||
else if (VpIsPosInf(m)) {
|
||||
*d = VpGetDoublePosInf();
|
||||
*e = 0;
|
||||
f = 2;
|
||||
goto Exit;
|
||||
} else
|
||||
if(VpIsNegInf(m)) {
|
||||
}
|
||||
else if (VpIsNegInf(m)) {
|
||||
*d = VpGetDoubleNegInf();
|
||||
*e = 0;
|
||||
f = 2;
|
||||
@ -5377,7 +5427,7 @@ VpVtoD(double *d, SIGNED_VALUE *e, Real *m)
|
||||
/* Normal number */
|
||||
fig = (DBLE_FIG + BASE_FIG - 1) / BASE_FIG;
|
||||
ind_m = 0;
|
||||
mm = Min(fig,(m->Prec));
|
||||
mm = Min(fig, m->Prec);
|
||||
*d = 0.0;
|
||||
div = 1.;
|
||||
while (ind_m < mm) {
|
||||
@ -5423,14 +5473,15 @@ VpDtoV(Real *m, double d)
|
||||
VpSetZero(m, 1);
|
||||
goto Exit;
|
||||
}
|
||||
val =(d > 0.) ? d :(-d);
|
||||
val = (d > 0.) ? d : -d;
|
||||
ne = 0;
|
||||
if (val >= 1.0) {
|
||||
while (val >= 1.0) {
|
||||
val /= (double)BASE;
|
||||
++ne;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
val2 = 1.0 / (double)BASE;
|
||||
while (val < val2) {
|
||||
val *= (double)BASE;
|
||||
@ -5505,7 +5556,8 @@ VpItoV(Real *m, SIGNED_VALUE ival)
|
||||
}
|
||||
val = val - v2 * v1;
|
||||
v = v1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
v = 0;
|
||||
}
|
||||
m->frac[ind_m] = v;
|
||||
@ -5606,11 +5658,10 @@ VpSqrt(Real *y, Real *x)
|
||||
VpAsgn(y, r, 1); /* y = r */
|
||||
if (f->exponent <= prec) goto converge;
|
||||
} while(++nr < n);
|
||||
/* */
|
||||
|
||||
#ifdef BIGDECIMAL_DEBUG
|
||||
if (gfDebug) {
|
||||
printf("ERROR(VpSqrt): did not converge within %ld iterations.\n",
|
||||
nr);
|
||||
printf("ERROR(VpSqrt): did not converge within %ld iterations.\n", nr);
|
||||
}
|
||||
#endif /* BIGDECIMAL_DEBUG */
|
||||
y->MaxPrec = y_prec;
|
||||
@ -5660,7 +5711,7 @@ VpMidRound(Real *y, unsigned short f, ssize_t nf)
|
||||
exptoadd=0;
|
||||
if (nf < 0) {
|
||||
/* rounding position too left(large). */
|
||||
if((f!=VP_ROUND_CEIL) && (f!=VP_ROUND_FLOOR)) {
|
||||
if (f != VP_ROUND_CEIL && f != VP_ROUND_FLOOR) {
|
||||
VpSetZero(y, VpGetSign(y)); /* truncate everything */
|
||||
return 0;
|
||||
}
|
||||
@ -5684,13 +5735,18 @@ VpMidRound(Real *y, unsigned short f, ssize_t nf)
|
||||
|
||||
nf is now position (in decimal places) of the digit from the start of
|
||||
the array.
|
||||
|
||||
ix is the position (in BDIGITS) of the BDIGIT containing the decimal digit,
|
||||
from the start of the array.
|
||||
|
||||
v is the value of this BDIGIT
|
||||
|
||||
ioffset is the number of extra decimal places along of this decimal digit
|
||||
within v.
|
||||
|
||||
n is the number of decimal digits remaining within v after this decimal digit
|
||||
shifter is 10**n,
|
||||
|
||||
v % shifter are the remaining digits within v
|
||||
v % (shifter * 10) are the digit together with the remaining digits within v
|
||||
v / shifter are the digit's predecessors together with the digit
|
||||
@ -5775,14 +5831,16 @@ VpMidRound(Real *y, unsigned short f, ssize_t nf)
|
||||
if (ix) {
|
||||
y->frac[ix] = 0;
|
||||
VpRdup(y, ix);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
short s = VpGetSign(y);
|
||||
SIGNED_VALUE e = y->exponent;
|
||||
VpSetOne(y);
|
||||
VpSetSign(y, s);
|
||||
y->exponent = e + 1;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
y->frac[ix] = div;
|
||||
VpNmlz(y);
|
||||
}
|
||||
@ -5892,7 +5950,7 @@ VpRdup(Real *m, size_t ind_m)
|
||||
if (!ind_m) ind_m = m->Prec;
|
||||
|
||||
carry = 1;
|
||||
while (carry > 0 && (ind_m--)) {
|
||||
while (carry > 0 && ind_m--) {
|
||||
m->frac[ind_m] += carry;
|
||||
if (m->frac[ind_m] >= BASE) m->frac[ind_m] -= BASE;
|
||||
else carry = 0;
|
||||
@ -5900,7 +5958,8 @@ VpRdup(Real *m, size_t ind_m)
|
||||
if (carry > 0) { /* Overflow,count exponent and set fraction part be 1 */
|
||||
if (!AddExponent(m, 1)) return 0;
|
||||
m->Prec = m->frac[0] = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpNmlz(m);
|
||||
}
|
||||
return 1;
|
||||
@ -5973,10 +6032,11 @@ VpPower(Real *y, Real *x, SIGNED_VALUE n)
|
||||
sign = VpGetSign(x);
|
||||
if (n < 0) {
|
||||
n = -n;
|
||||
if(sign<0) sign = (n%2)?(-1):(1);
|
||||
if (sign < 0) sign = (n % 2) ? -1 : 1;
|
||||
VpSetInf(y, sign);
|
||||
} else {
|
||||
if(sign<0) sign = (n%2)?(-1):(1);
|
||||
}
|
||||
else {
|
||||
if (sign < 0) sign = (n % 2) ? -1 : 1;
|
||||
VpSetZero(y,sign);
|
||||
}
|
||||
goto Exit;
|
||||
@ -5998,7 +6058,7 @@ VpPower(Real *y, Real *x, SIGNED_VALUE n)
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if((x->exponent == 1) &&(x->Prec == 1) &&(x->frac[0] == 1)) {
|
||||
if (x->exponent == 1 && x->Prec == 1 && x->frac[0] == 1) {
|
||||
/* abs(x) = 1 */
|
||||
VpSetOne(y);
|
||||
if (VpGetSign(x) > 0) goto Exit;
|
||||
@ -6011,7 +6071,8 @@ VpPower(Real *y, Real *x, SIGNED_VALUE n)
|
||||
else if (n < 0) {
|
||||
sign = -1;
|
||||
n = -n;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
VpSetOne(y);
|
||||
goto Exit;
|
||||
}
|
||||
@ -6072,13 +6133,13 @@ VpVarCheck(Real * v)
|
||||
v->MaxPrec);
|
||||
return 1;
|
||||
}
|
||||
if((v->Prec <= 0) ||((v->Prec) >(v->MaxPrec))) {
|
||||
if (v->Prec <= 0 || v->Prec > v->MaxPrec) {
|
||||
printf("ERROR(VpVarCheck): Illegal Precision(=%"PRIuSIZE")\n", v->Prec);
|
||||
printf(" Max. Prec.=%"PRIuSIZE"\n", v->MaxPrec);
|
||||
return 2;
|
||||
}
|
||||
for (i = 0; i < v->Prec; ++i) {
|
||||
if((v->frac[i] >= BASE)) {
|
||||
if (v->frac[i] >= BASE) {
|
||||
printf("ERROR(VpVarCheck): Illegal fraction\n");
|
||||
printf(" Frac[%"PRIuSIZE"]=%lu\n", i, v->frac[i]);
|
||||
printf(" Prec. =%"PRIuSIZE"\n", v->Prec);
|
||||
|
Loading…
x
Reference in New Issue
Block a user