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

Function decShowNum

extern/decNumber/decCommon.c:1788–1838  ·  view source on GitHub ↗

---------------------------------------------------------------- */ decShowNum -- display bcd8 number in debug form */ / num is the bcdnum to display */ tag is a string to label the display */ ---------------------------------------------------------------- */

Source from the content-addressed store, hash-verified

1786 /* tag is a string to label the display */
1787 /* ---------------------------------------------------------------- */
1788 void decShowNum(const bcdnum *num, const char *tag) {
1789 const char *csign="+"; // sign character
1790 uByte *ub; // work
1791 uInt uiwork; // for macros
1792 if (num->sign==DECFLOAT_Sign) csign="-";
1793
1794 printf(">%s> ", tag);
1795 if (num->exponent==DECFLOAT_Inf) printf("%sInfinity", csign);
1796 else if (num->exponent==DECFLOAT_qNaN) printf("%sqNaN", csign);
1797 else if (num->exponent==DECFLOAT_sNaN) printf("%ssNaN", csign);
1798 else { // finite
1799 char qbuf[10]; // for right-aligned q
1800 char *c; // work
1801 const uByte *u; // ..
1802 Int e=num->exponent; // .. exponent
1803 strcpy(qbuf, "q=");
1804 c=&qbuf[2]; // where exponent will go
1805 // lay out the exponent
1806 if (e<0) {
1807 *c++='-'; // add '-'
1808 e=-e; // uInt, please
1809 }
1810 #if DECEMAXD>4
1811 #error Exponent form is too long for ShowNum to lay out
1812 #endif
1813 if (e==0) *c++='0'; // 0-length case
1814 else if (e<1000) { // 3 (or fewer) digits case
1815 u=&BIN2BCD8[e*4]; // -> 3 digits + length byte
1816 UBFROMUI(c, UBTOUI(u+3-*(u+3))|CHARMASK); // [as above]
1817 c+=*(u+3); // bump pointer appropriately
1818 }
1819 else { // 4-digits
1820 Int thou=((e>>3)*1049)>>17; // e/1000
1821 Int rem=e-(1000*thou); // e%1000
1822 *c++=(char)('0'+(char)thou); // the thousands digit
1823 u=&BIN2BCD8[rem*4]; // -> 3 digits + length byte
1824 UBFROMUI(c, UBTOUI(u)|CHARMASK); // copy fixed 3+1 characters [is safe]
1825 c+=3; // bump pointer, always 3 digits
1826 }
1827 *c='\0'; // add terminator
1828 printf("%7s c=%s", qbuf, csign);
1829 }
1830
1831 if (!EXPISSPECIAL(num->exponent) || num->msd!=num->lsd || *num->lsd!=0) {
1832 for (ub=num->msd; ub<=num->lsd; ub++) { // coefficient...
1833 printf("%1x", *ub);
1834 if ((num->lsd-ub)%3==0 && ub!=num->lsd) printf(" "); // 4-space
1835 }
1836 }
1837 printf("\n");
1838 } // decShowNum
1839#endif

Callers 3

decFiniteMultiplyFunction · 0.85
decFloatAddFunction · 0.85
decFloatQuantizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected