MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / decFloatFromPackedChecked

Function decFloatFromPackedChecked

extern/decNumber/decCommon.c:708–752  ·  view source on GitHub ↗

------------------------------------------------------------------ */ decFloatFromPackedChecked -- set from exponent and packed; checked */ / df is the target decFloat */ exp is the in-range unbiased exponent, q, or a special value in */ the form returned by decFloatGetExponent */ packed holds DECPMAX packed decimal digits plus a sig

Source from the content-addressed store, hash-verified

706/* No status will be set. */
707/* ------------------------------------------------------------------ */
708decFloat * decFloatFromPackedChecked(decFloat *df, Int exp,
709 const uByte *packed) {
710 uByte bcdar[DECPMAX+2]; // work [+1 for pad, +1 for sign]
711 const uByte *ip; // ..
712 uByte *op; // ..
713 Int sig=0; // sign
714
715 // expand coefficient and sign to BCDAR
716 #if SINGLE
717 op=bcdar+1; // no pad digit
718 #else
719 op=bcdar; // first (pad) digit here
720 #endif
721 for (ip=packed; ip<packed+((DECPMAX+2)/2); ip++) {
722 *op=*ip>>4;
723 if (*op>9) return NULL;
724 op++;
725 *op=(uByte)(*ip&0x0f); // [final nibble is sign]
726 if (*op>9 && ip<packed+((DECPMAX+2)/2)-1) return NULL;
727 op++;
728 }
729 op--; // -> sign byte
730 if (*op<=9) return NULL; // bad sign
731 if (*op==DECPMINUS || *op==DECPMINUSALT) sig=DECFLOAT_Sign;
732
733 #if !SINGLE
734 if (bcdar[0]!=0) return NULL; // bad pad nibble
735 #endif
736
737 if (EXPISNAN(exp)) { // a NaN
738 if (bcdar[1]!=0) return NULL; // bad msd
739 } // NaN
740 else if (EXPISINF(exp)) { // is infinite
741 Int i;
742 for (i=0; i<DECPMAX; i++) {
743 if (bcdar[i+1]!=0) return NULL; // should be all zeros
744 }
745 } // infinity
746 else { // finite
747 // check the exponent is in range
748 if (exp>DECEMAX-DECPMAX+1) return NULL;
749 if (exp<DECEMIN-DECPMAX+1) return NULL;
750 }
751 return decFloatFromBCD(df, exp, bcdar+1, sig);
752 } // decFloatFromPacked
753
754/* ------------------------------------------------------------------ */
755/* decFloatFromString -- conversion from numeric string */

Callers

nothing calls this directly

Calls 1

decFloatFromBCDFunction · 0.85

Tested by

no test coverage detected