2 * dolfptoa - do the grunge work of converting an l_fp number to decimal
7 #include "lib_strbuf.h"
8 #include "ntp_string.h"
9 #include "ntp_stdlib.h"
20 register u_char *cp, *cpend;
21 register u_long lwork;
29 * Get a string buffer before starting
34 * Zero the character buffer
36 memset((char *) cbuf, 0, sizeof(cbuf));
39 * Work on the integral part. This is biased by what I know
40 * compiles fairly well for a 68000.
42 cp = cpend = &cbuf[10];
44 if (lwork & 0xffff0000) {
45 register u_long lten = 10;
51 ltmp -= (lwork << 3) + (lwork << 1);
53 } while (lwork & 0xffff0000);
56 register u_short sten = 10;
57 register u_short stmp;
58 register u_short swork = (u_short)lwork;
63 stmp -= (swork<<3) + (swork<<1);
69 * Done that, now deal with the problem of the fraction. First
70 * determine the number of decimal places.
87 * If there's a fraction to deal with, do so.
99 * The scheme here is to multiply the
100 * fraction (0.1234...) by ten. This moves
101 * a junk of BCD into the units part.
102 * record that and iterate.
110 *cpend++ = (u_char)work.l_ui;
118 if (work.l_uf & 0x80000000) {
119 register u_char *tp = cpend;
134 * We've now got the fraction in cbuf[], with cp pointing at
135 * the first character, cpend pointing past the last, and
136 * cpdec pointing at the first character past the decimal.
137 * Remove leading zeros, then format the number into the
154 *bp++ = (char)(*cp++ + '0'); /* ascii dependent? */