2 * dofptoa - do the grunge work to convert an fp number to ascii
8 #include "lib_strbuf.h"
9 #include "ntp_string.h"
10 #include "ntp_stdlib.h"
20 register u_char *cp, *cpend;
29 * Get a string buffer before starting
39 * Set the pointers to point at the first
40 * decimal place. Get a local copy of the value.
42 cp = cpend = &cbuf[5];
46 * If we have to, decode the integral part
48 if (!(val & 0xffff0000))
51 register u_short sv = (u_short)(val >> 16);
53 register u_short ten = 10;
57 sv = (u_short) (sv/ten);
58 *(--cp) = (u_char)(tmp - ((sv<<3) + (sv<<1)));
63 * Figure out how much of the fraction to do
66 dec = (short)(ndec + 3);
81 val = (val << 3) + (val << 1);
82 *cpend++ = (u_char)(val >> 16);
100 * Remove leading zeroes if necessary
102 while (cp < (cpdec -1) && *cp == 0)
106 * Copy it into the buffer, asciizing as we go.
115 *bp++ = (char)(*cp++ + '0');
133 plusfp = (u_fp)(-fpv);
138 return dofptoa(plusfp, (neg?'-':0), ndec, FALSE);
153 plusfp = (u_fp)(-fpv);
158 return dofptoa(plusfp, (neg?'-':0), ndec, TRUE);