Lines Matching refs:dn
366 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromInt32(decNumber *dn, Int in) { in uprv_decNumberFromInt32() argument
374 uprv_decNumberFromUInt32(dn, unsig); in uprv_decNumberFromInt32()
375 if (in<0) dn->bits=DECNEG; /* sign needed */ in uprv_decNumberFromInt32()
376 return dn; in uprv_decNumberFromInt32()
379 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromUInt32(decNumber *dn, uInt uin) { in uprv_decNumberFromUInt32() argument
381 uprv_decNumberZero(dn); /* clean */ in uprv_decNumberFromUInt32()
382 if (uin==0) return dn; /* [or decGetDigits bad call] */ in uprv_decNumberFromUInt32()
383 for (up=dn->lsu; uin>0; up++) { in uprv_decNumberFromUInt32()
387 dn->digits=decGetDigits(dn->lsu, up-dn->lsu); in uprv_decNumberFromUInt32()
388 return dn; in uprv_decNumberFromUInt32()
401 U_CAPI Int U_EXPORT2 uprv_decNumberToInt32(const decNumber *dn, decContext *set) { in uprv_decNumberToInt32() argument
403 if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0; in uprv_decNumberToInt32()
407 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0) ; /* bad */ in uprv_decNumberToInt32()
412 up=dn->lsu; /* -> lsu */ in uprv_decNumberToInt32()
420 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1]; in uprv_decNumberToInt32()
424 if (dn->bits&DECNEG && hi==214748364 && lo==8) return 0x80000000; in uprv_decNumberToInt32()
429 if (dn->bits&DECNEG) return -i; in uprv_decNumberToInt32()
437 U_CAPI uInt U_EXPORT2 uprv_decNumberToUInt32(const decNumber *dn, decContext *set) { in uprv_decNumberToUInt32() argument
439 if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0; in uprv_decNumberToUInt32()
442 if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0 in uprv_decNumberToUInt32()
443 || (dn->bits&DECNEG && !ISZERO(dn))); /* bad */ in uprv_decNumberToUInt32()
448 up=dn->lsu; /* -> lsu */ in uprv_decNumberToUInt32()
456 for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1]; in uprv_decNumberToUInt32()
480 U_CAPI char * U_EXPORT2 uprv_decNumberToString(const decNumber *dn, char *string){ in uprv_decNumberToString() argument
481 decToString(dn, string, 0); in uprv_decNumberToString()
485 U_CAPI char * U_EXPORT2 uprv_decNumberToEngString(const decNumber *dn, char *string){ in uprv_decNumberToEngString() argument
486 decToString(dn, string, 1); in uprv_decNumberToEngString()
510 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromString(decNumber *dn, const char chars[], in uprv_decNumberFromString() argument
532 return uprv_decNumberZero(dn); in uprv_decNumberFromString()
568 uprv_decNumberZero(dn); /* be optimistic */ in uprv_decNumberFromString()
571 dn->bits=bits | DECINF; in uprv_decNumberFromString()
577 dn->bits=bits | DECNAN; /* assume simple NaN */ in uprv_decNumberFromString()
580 dn->bits=bits | DECSNAN; in uprv_decNumberFromString()
609 bits=dn->bits; /* for copy-back */ in uprv_decNumberFromString()
659 uprv_decNumberZero(dn); /* clean result */ in uprv_decNumberFromString()
672 if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */ in uprv_decNumberFromString()
713 dn->bits=bits; in uprv_decNumberFromString()
714 dn->exponent=exponent; in uprv_decNumberFromString()
715 dn->digits=d; in uprv_decNumberFromString()
720 decSetCoeff(dn, set, res, d, &residue, &status); in uprv_decNumberFromString()
722 decFinalize(dn, set, &residue, &status); in uprv_decNumberFromString()
726 if ((dn->exponent-1<set->emin-dn->digits) in uprv_decNumberFromString()
727 || (dn->exponent-1>set->emax-set->digits)) { in uprv_decNumberFromString()
729 decFinalize(dn, set, &residue, &status); in uprv_decNumberFromString()
736 if (status!=0) decStatus(dn, status, set); in uprv_decNumberFromString()
737 return dn; in uprv_decNumberFromString()
3209 decNumber dn; in uprv_decNumberToIntegralExact() local
3229 uprv_decNumberZero(&dn); /* make a number with exponent 0 */ in uprv_decNumberToIntegralExact()
3230 uprv_decNumberQuantize(res, rhs, &dn, &workset); in uprv_decNumberToIntegralExact()
3328 enum decClass uprv_decNumberClass(const decNumber *dn, decContext *set) { in uprv_decNumberClass() argument
3329 if (decNumberIsSpecial(dn)) { in uprv_decNumberClass()
3330 if (decNumberIsQNaN(dn)) return DEC_CLASS_QNAN; in uprv_decNumberClass()
3331 if (decNumberIsSNaN(dn)) return DEC_CLASS_SNAN; in uprv_decNumberClass()
3333 if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_INF; in uprv_decNumberClass()
3337 if (uprv_decNumberIsNormal(dn, set)) { /* most common */ in uprv_decNumberClass()
3338 if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_NORMAL; in uprv_decNumberClass()
3342 if (decNumberIsZero(dn)) { /* most common */ in uprv_decNumberClass()
3343 if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_ZERO; in uprv_decNumberClass()
3346 if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_SUBNORMAL; in uprv_decNumberClass()
3486 U_CAPI uByte * U_EXPORT2 uprv_decNumberGetBCD(const decNumber *dn, uByte *bcd) { in uprv_decNumberGetBCD() argument
3487 uByte *ub=bcd+dn->digits-1; /* -> lsd */ in uprv_decNumberGetBCD()
3488 const Unit *up=dn->lsu; /* Unit pointer, -> lsu */ in uprv_decNumberGetBCD()
3520 U_CAPI decNumber * U_EXPORT2 uprv_decNumberSetBCD(decNumber *dn, const uByte *bcd, uInt n) { in uprv_decNumberSetBCD() argument
3521 Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */ in uprv_decNumberSetBCD()
3529 for (;up>=dn->lsu; up--) { /* each Unit from msu */ in uprv_decNumberSetBCD()
3535 dn->digits=n; /* set digit count */ in uprv_decNumberSetBCD()
3536 return dn; in uprv_decNumberSetBCD()
3545 Int uprv_decNumberIsNormal(const decNumber *dn, decContext *set) { in uprv_decNumberIsNormal() argument
3548 if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0; in uprv_decNumberIsNormal()
3551 if (decNumberIsSpecial(dn)) return 0; /* not finite */ in uprv_decNumberIsNormal()
3552 if (decNumberIsZero(dn)) return 0; /* not non-zero */ in uprv_decNumberIsNormal()
3554 ae=dn->exponent+dn->digits-1; /* adjusted exponent */ in uprv_decNumberIsNormal()
3565 Int uprv_decNumberIsSubnormal(const decNumber *dn, decContext *set) { in uprv_decNumberIsSubnormal() argument
3568 if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0; in uprv_decNumberIsSubnormal()
3571 if (decNumberIsSpecial(dn)) return 0; /* not finite */ in uprv_decNumberIsSubnormal()
3572 if (decNumberIsZero(dn)) return 0; /* not non-zero */ in uprv_decNumberIsSubnormal()
3574 ae=dn->exponent+dn->digits-1; /* adjusted exponent */ in uprv_decNumberIsSubnormal()
3589 U_CAPI decNumber * U_EXPORT2 uprv_decNumberTrim(decNumber *dn) { in uprv_decNumberTrim() argument
3593 if (decCheckOperands(DECUNRESU, DECUNUSED, dn, DECUNCONT)) return dn; in uprv_decNumberTrim()
3596 return decTrim(dn, &set, 0, 1, &dropped); in uprv_decNumberTrim()
3617 U_CAPI decNumber * U_EXPORT2 uprv_decNumberZero(decNumber *dn) { in uprv_decNumberZero() argument
3620 if (decCheckOperands(dn, DECUNUSED, DECUNUSED, DECUNCONT)) return dn; in uprv_decNumberZero()
3623 dn->bits=0; in uprv_decNumberZero()
3624 dn->exponent=0; in uprv_decNumberZero()
3625 dn->digits=1; in uprv_decNumberZero()
3626 dn->lsu[0]=0; in uprv_decNumberZero()
3627 return dn; in uprv_decNumberZero()
3650 static void decToString(const decNumber *dn, char *string, Flag eng) { in decToString() argument
3651 Int exp=dn->exponent; /* local copy */ in decToString()
3656 const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */ in decToString()
3660 if (decCheckOperands(DECUNRESU, dn, DECUNUSED, DECUNCONT)) { in decToString()
3665 if (decNumberIsNegative(dn)) { /* Negatives get a minus */ in decToString()
3669 if (dn->bits&DECSPECIAL) { /* Is a special value */ in decToString()
3670 if (decNumberIsInfinite(dn)) { in decToString()
3675 if (dn->bits&DECSNAN) { /* signalling NaN */ in decToString()
3683 if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return; in decToString()
3688 cut=MSUDIGITS(dn->digits); /* [faster than remainder] */ in decToString()
3692 for (;up>=dn->lsu; up--) { /* each Unit from msu */ in decToString()
3701 pre=dn->digits+exp; /* digits before '.' */ in decToString()
3704 e=exp+dn->digits-1; /* calculate E value */ in decToString()
3721 if (!ISZERO(dn)) pre+=adj; in decToString()
3737 if (up==dn->lsu) break; /* out of input digits (pre>digits) */ in decToString()
3744 if (n<dn->digits) { /* more to come, after '.' */ in decToString()
3748 if (up==dn->lsu) break; /* out of input digits */ in decToString()
3764 if (up==dn->lsu) break; /* out of input digits */ in decToString()
6633 static decNumber * decTrim(decNumber *dn, decContext *set, Flag all, argument
6640 if (decCheckOperands(dn, DECUNUSED, DECUNUSED, DECUNCONT)) return dn;
6644 if ((dn->bits & DECSPECIAL) /* fast exit if special .. */
6645 || (*dn->lsu & 0x01)) return dn; /* .. or odd */
6646 if (ISZERO(dn)) { /* .. or 0 */
6647 dn->exponent=0; /* (sign is preserved) */
6648 return dn;
6652 exp=dn->exponent;
6654 up=dn->lsu; /* -> current Unit */
6655 for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
6677 if (d==0) return dn; /* none to drop */
6681 Int maxd=set->emax-set->digits+1-dn->exponent;
6682 if (maxd<=0) return dn; /* nothing possible */
6687 decShiftToLeast(dn->lsu, D2U(dn->digits), d);
6688 dn->exponent+=d; /* maintain numerical value */
6689 dn->digits-=d; /* new length */
6691 return dn;
6849 static decNumber *decRoundOperand(const decNumber *dn, decContext *set, argument
6863 decCopyFit(res, dn, set, &residue, &newstatus);
6931 static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu, argument
6944 if (dn->lsu!=lsu) { /* copy needed */
6948 for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
6950 dn->digits=len; /* set the new length */
6958 dn->exponent+=discard; /* maintain numerical value */
6973 *dn->lsu=0; /* coefficient will now be 0 */
6974 dn->digits=1; /* .. */
7004 *dn->lsu=0; /* .. result is 0 */
7005 dn->digits=1; /* .. */
7009 dn->digits=count; /* set the new length */
7012 for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
7050 *dn->lsu=0; /* .. result is 0 */
7051 dn->digits=1; /* .. */
7055 dn->digits=count; /* set the new length */
7057 for (target=dn->lsu; ; target++) {
7113 static void decApplyRound(decNumber *dn, decContext *set, Int residue, argument
7130 Int lsd5=*dn->lsu%5; /* get lsd and quintate */
7149 if (*dn->lsu & 0x01) bump=1;
7164 if (decNumberIsNegative(dn)) {
7175 if (!decNumberIsNegative(dn)) {
7201 uInt count=dn->digits; /* digits to be checked */
7202 for (up=dn->lsu; ; up++) {
7208 for (up=up-1; up>=dn->lsu; up--) *up=0; /* others all to 0 */
7209 dn->exponent++; /* and bump exponent */
7211 if ((dn->exponent+dn->digits)>set->emax+1) {
7212 decSetOverflow(dn, set, status);
7225 uInt count=dn->digits; /* digits to be checked */
7226 for (up=dn->lsu; ; up++) {
7234 for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
7235 dn->exponent--; /* and bump exponent */
7242 if (dn->exponent+1==set->emin-set->digits+1) {
7243 if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
7246 dn->digits--;
7248 dn->exponent++;
7262 decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
7282 static void decFinish(decNumber *dn, decContext *set, Int *residue, argument
7285 if ISZERO(dn) { /* value is zero */
7286 dn->exponent=0; /* clean exponent .. */
7287 dn->bits=0; /* .. and sign */
7290 if (dn->exponent>=0) { /* non-negative exponent */
7292 if (set->digits >= (dn->exponent+dn->digits)) {
7293 dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
7294 dn->exponent=0;
7299 decFinalize(dn, set, residue, status);
7317 static void decFinalize(decNumber *dn, decContext *set, Int *residue, argument
7320 Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
7328 if (dn->exponent<=tinyexp) { /* prefilter */
7332 if (dn->exponent<tinyexp) {
7334 decSetSubnormal(dn, set, residue, status);
7341 comp=decCompare(dn, &nmin, 1); /* (signless compare) */
7347 decApplyRound(dn, set, *residue, status); /* might force down */
7348 decSetSubnormal(dn, set, residue, status);
7354 if (*residue!=0) decApplyRound(dn, set, *residue, status);
7357 if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
7361 if (dn->exponent>set->emax-dn->digits+1) { /* too big */
7362 decSetOverflow(dn, set, status);
7369 shift=dn->exponent-(set->emax-set->digits+1);
7372 if (!ISZERO(dn)) {
7373 dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
7375 dn->exponent-=shift; /* adjust the exponent to match */
7391 static void decSetOverflow(decNumber *dn, decContext *set, uInt *status) { argument
7393 uByte sign=dn->bits&DECNEG; /* clean and save sign bit */
7395 if (ISZERO(dn)) { /* zero does not overflow magnitude */
7398 if (dn->exponent>emax) { /* clamp required */
7399 dn->exponent=emax;
7405 uprv_decNumberZero(dn);
7422 decSetMaxValue(dn, set);
7423 dn->bits=sign; /* set sign */
7425 else dn->bits=sign|DECINF; /* Value is +/-Infinity */
7437 static void decSetMaxValue(decNumber *dn, decContext *set) { argument
7440 dn->digits=count;
7442 for (up=dn->lsu; ; up++) {
7450 dn->bits=0; /* + sign */
7451 dn->exponent=set->emax-set->digits+1;
7471 static void decSetSubnormal(decNumber *dn, decContext *set, Int *residue, argument
7479 uprv_decNumberZero(dn);
7490 if ISZERO(dn) { /* value is zero */
7498 if (dn->exponent<etiny) { /* clamp required */
7499 dn->exponent=etiny;
7506 adjust=etiny-dn->exponent; /* calculate digits to remove */
7518 workset.digits=dn->digits-adjust; /* set requested length */
7521 decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
7522 decApplyRound(dn, &workset, *residue, status);
7530 if (dn->exponent>etiny) {
7531 dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
7532 dn->exponent--; /* (re)adjust the exponent. */
7536 if (ISZERO(dn)) *status|=DEC_Clamped;
7585 static Int decGetInt(const decNumber *dn) { argument
7589 Int ilength=dn->digits+dn->exponent; /* integral length */
7590 Flag neg=decNumberIsNegative(dn); /* 1 if -ve */
7600 if (ISZERO(dn)) return 0; /* zeros are OK, with any exponent */
7602 up=dn->lsu; /* ready for lsu */
7604 if (dn->exponent>=0) { /* relatively easy */
7606 got=dn->exponent;
7609 Int count=-dn->exponent; /* digits to discard */
7674 static decNumber *decDecap(decNumber *dn, Int drop) { argument
7677 if (drop>=dn->digits) { /* losing the whole thing */
7679 if (drop>dn->digits)
7681 (LI)drop, (LI)dn->digits);
7683 dn->lsu[0]=0;
7684 dn->digits=1;
7685 return dn;
7687 msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
7688 cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
7691 dn->digits=decGetDigits(dn->lsu, msu-dn->lsu+1);
7692 return dn;
7784 static void decStatus(decNumber *dn, uInt status, decContext *set) { argument
7789 uprv_decNumberZero(dn); /* other error: clean throughout */
7790 dn->bits=DECNAN; /* and make a quiet NaN */
7856 void uprv_decNumberShow(const decNumber *dn) { argument
7861 if (dn==NULL) {
7864 if (decNumberIsNegative(dn)) isign='-';
7866 if (dn->bits&DECSPECIAL) { /* Is a special value */
7867 if (decNumberIsInfinite(dn)) printf("Infinity");
7869 if (dn->bits&DECSNAN) printf("sNaN"); /* signalling NaN */
7873 if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
7881 up=dn->lsu+D2U(dn->digits)-1; /* msu */
7883 for (up=up-1; up>=dn->lsu; up--) {
7892 if (dn->exponent!=0) {
7894 if (dn->exponent<0) esign='-';
7895 printf(" E%c%ld", esign, (LI)abs(dn->exponent));
7897 printf(" [%ld]\n", (LI)dn->digits);
7999 static Flag decCheckNumber(const decNumber *dn) { argument
8005 if (dn==NULL) { /* hopeless */
8013 if (dn->bits & DECSPECIAL) {
8014 if (dn->exponent!=0) {
8017 (LI)dn->exponent, dn->bits);
8022 if (decNumberIsInfinite(dn)) {
8023 if (dn->digits!=1) {
8025 printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
8028 if (*dn->lsu!=0) {
8030 printf("LSU %ld (not 0) for an infinity.\n", (LI)*dn->lsu);
8032 decDumpAr('I', dn->lsu, D2U(dn->digits));
8041 if (dn->digits<1 || dn->digits>DECNUMMAXP) {
8043 printf("Digits %ld in number.\n", (LI)dn->digits);
8047 d=dn->digits;
8049 for (up=dn->lsu; d>0; up++) {
8053 if (dn->digits>1 && *up<powers[d-1]) {
8056 uprv_decNumberShow(dn);
8063 (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
8072 ae=dn->exponent+dn->digits-1; /* adjusted exponent */
8079 uprv_decNumberShow(dn);
8085 uprv_decNumberShow(dn);
8100 static void decCheckInexact(const decNumber *dn, decContext *set) { argument
8103 && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
8106 (LI)dn->digits);
8107 uprv_decNumberShow(dn);
8113 if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;