2 * dofptoa - do the grunge work to convert an fp number to ascii
7 #include "lib_strbuf.h"
8 #include "ntp_string.h"
9 #include "ntp_stdlib.h"
19 register u_char *cp, *cpend;
28 * Get a string buffer before starting
35 memset((char *)cbuf, 0, sizeof cbuf);
38 * Set the pointers to point at the first
39 * decimal place. Get a local copy of the value.
41 cp = cpend = &cbuf[5];
45 * If we have to, decode the integral part
47 if (!(val & 0xffff0000))
50 register u_short sv = (u_short)(val >> 16);
52 register u_short ten = 10;
56 sv = (u_short) (sv/ten);
57 *(--cp) = (u_char)(tmp - ((sv<<3) + (sv<<1)));
62 * Figure out how much of the fraction to do
65 dec = (short)(ndec + 3);
80 val = (val << 3) + (val << 1);
81 *cpend++ = (u_char)(val >> 16);
99 * Remove leading zeroes if necessary
101 while (cp < (cpdec -1) && *cp == 0)
105 * Copy it into the buffer, asciizing as we go.
114 *bp++ = (char)(*cp++ + '0');