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

Function decFloatToString

extern/decNumber/decCommon.c:1504–1702  ·  view source on GitHub ↗

------------------------------------------------------------------ */ decFloatToString -- conversion to numeric string */ / df is the decFloat format number to convert */ string is the string where the result will be laid out */ / string must be at least DECPMAX+9 characters (the worst case is */ "-0.00000nnn...nnn\0", which is as long as the e

Source from the content-addressed store, hash-verified

1502/* No error is possible, and no status will be set */
1503/* ------------------------------------------------------------------ */
1504char * decFloatToString(const decFloat *df, char *string){
1505 uInt msd; // coefficient MSD
1506 Int exp; // exponent top two bits or full
1507 uInt comb; // combination field
1508 char *cstart; // coefficient start
1509 char *c; // output pointer in string
1510 char *s, *t; // .. (source, target)
1511 Int pre, e; // work
1512 const uByte *u; // ..
1513 uInt uiwork; // for macros [one compiler needs
1514 // volatile here to avoid bug, but
1515 // that doubles execution time]
1516
1517 // Source words; macro handles endianness
1518 uInt sourhi=DFWORD(df, 0); // word with sign
1519 #if DECPMAX==16
1520 uInt sourlo=DFWORD(df, 1);
1521 #elif DECPMAX==34
1522 uInt sourmh=DFWORD(df, 1);
1523 uInt sourml=DFWORD(df, 2);
1524 uInt sourlo=DFWORD(df, 3);
1525 #endif
1526
1527 c=string; // where result will go
1528 if (((Int)sourhi)<0) *c++='-'; // handle sign
1529 comb=sourhi>>26; // sign+combination field
1530 msd=DECCOMBMSD[comb]; // decode the combination field
1531 exp=DECCOMBEXP[comb]; // ..
1532
1533 if (!EXPISSPECIAL(exp)) { // finite
1534 // complete exponent; top two bits are in place
1535 exp+=GETECON(df)-DECBIAS; // .. + continuation and unbias
1536 }
1537 else { // IS special
1538 if (exp==DECFLOAT_Inf) { // infinity
1539 strcpy(c, "Infinity");
1540 return string; // easy
1541 }
1542 if (sourhi&0x02000000) *c++='s'; // sNaN
1543 strcpy(c, "NaN"); // complete word
1544 c+=3; // step past
1545 // quick exit if the payload is zero
1546 #if DECPMAX==7
1547 if ((sourhi&0x000fffff)==0) return string;
1548 #elif DECPMAX==16
1549 if (sourlo==0 && (sourhi&0x0003ffff)==0) return string;
1550 #elif DECPMAX==34
1551 if (sourlo==0 && sourml==0 && sourmh==0
1552 && (sourhi&0x00003fff)==0) return string;
1553 #endif
1554 // otherwise drop through to add integer; set correct exp etc.
1555 exp=0; msd=0; // setup for following code
1556 }
1557
1558 /* convert the digits of the significand to characters */
1559 cstart=c; // save start of coefficient
1560 if (msd) *c++=(char)('0'+(char)msd); // non-zero most significant digit
1561

Callers 1

decFloatShowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected