*up=(Unit)(uin%(DECDPUNMAX+1));
uin=uin/(DECDPUNMAX+1);
}
- dn->digits=decGetDigits(dn->lsu, up-dn->lsu);
+ dn->digits=decGetDigits(dn->lsu, static_cast<int32_t>(up - dn->lsu));
return dn;
} /* decNumberFromUInt32 */
for (; *c=='0' && *(c+1)!='\0';) c++; /* strip insignificant zeros */
firstexp=c; /* save exponent digit place */
+ uInt uexponent = 0; /* Avoid undefined behavior on signed int overflow */
for (; ;c++) {
if (*c<'0' || *c>'9') break; /* not a digit */
- exponent=X10(exponent)+(Int)*c-(Int)'0';
+ uexponent=X10(uexponent)+(uInt)*c-(uInt)'0';
} /* c */
+ exponent = (Int)uexponent;
/* if not now on a '\0', *c must not be a digit */
if (*c!='\0') break;
/* Handle decimal point... */
if (dotchar!=NULL && dotchar<last) /* non-trailing '.' found? */
- exponent-=(last-dotchar); /* adjust exponent */
+ exponent -= static_cast<int32_t>(last-dotchar); /* adjust exponent */
/* [we can now ignore the .] */
/* OK, the digits string is good. Assemble in the decNumber, or in */
} /* both OK */
} /* each unit */
/* [here uc-1 is the msu of the result] */
- res->digits=decGetDigits(res->lsu, uc-res->lsu);
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc - res->lsu));
res->exponent=0; /* integer */
res->bits=0; /* sign=0 */
return res; /* [no status to set] */
} /* each digit */
} /* each unit */
/* [here uc-1 is the msu of the result] */
- res->digits=decGetDigits(res->lsu, uc-res->lsu);
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc - res->lsu));
res->exponent=0; /* integer */
res->bits=0; /* sign=0 */
return res; /* [no status to set] */
} /* non-zero */
} /* each unit */
/* [here uc-1 is the msu of the result] */
- res->digits=decGetDigits(res->lsu, uc-res->lsu);
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc-res->lsu));
res->exponent=0; /* integer */
res->bits=0; /* sign=0 */
return res; /* [no status to set] */
} /* whole units to rotate */
/* the rotation may have left an undetermined number of zeros */
/* on the left, so true length needs to be calculated */
- res->digits=decGetDigits(res->lsu, msumax-res->lsu+1);
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(msumax-res->lsu+1));
} /* rotate needed */
} /* rhs OK */
} /* numerics */
} /* non-zero */
} /* each unit */
/* [here uc-1 is the msu of the result] */
- res->digits=decGetDigits(res->lsu, uc-res->lsu);
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc-res->lsu));
res->exponent=0; /* integer */
res->bits=0; /* sign=0 */
return res; /* [no status to set] */
} /* p */
*up=(Unit)item; up++; /* [final needs no division] */
} /* lp */
- accunits=up-acc; /* count of units */
+ accunits = static_cast<int32_t>(up-acc); /* count of units */
}
else { /* here to use units directly, without chunking ['old code'] */
#endif
/* OK, all A and B processed; might still have carry or borrow */
/* return number of Units in the result, negated if a borrow */
- if (carry==0) return c-clsu; /* no carry, so no more to do */
+ if (carry==0) return static_cast<int32_t>(c-clsu); /* no carry, so no more to do */
if (carry>0) { /* positive carry */
*c=(Unit)carry; /* place as new unit */
c++; /* .. */
- return c-clsu;
+ return static_cast<int32_t>(c-clsu);
}
/* -ve carry: it's a borrow; complement needed */
add=1; /* temporary carry... */
*c=(Unit)(add-carry-1);
c++; /* interesting, include it */
}
- return clsu-c; /* -ve result indicates borrowed */
+ return static_cast<int32_t>(clsu-c); /* -ve result indicates borrowed */
} /* decUnitAddSub */
/* ------------------------------------------------------------------ */
if (cut==DECDPUN) { /* unit-boundary case; easy */
up=uar+D2U(shift);
for (; up<uar+units; target++, up++) *target=*up;
- return target-uar;
+ return static_cast<int32_t>(target-uar);
}
/* messier */
count-=cut;
if (count<=0) break;
}
- return target-uar+1;
+ return static_cast<int32_t>(target-uar+1);
} /* decShiftToLeast */
#if DECSUBSET
cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
/* that may have left leading zero digits, so do a proper count... */
- dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
+ dn->digits=decGetDigits(dn->lsu, static_cast<int32_t>(msu-dn->lsu+1));
return dn;
} /* decDecap */