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 * safeguard against sign extensions and other mishaps on 64 bit platforms
40 * the code following is designed for and only for 32-bit inputs and
41 * only 32-bit worth of input are supplied.
47 * Work on the integral part. This is biased by what I know
48 * compiles fairly well for a 68000.
50 cp = cpend = &cbuf[10];
52 if (lwork & 0xffff0000) {
53 register u_long lten = 10;
59 ltmp -= (lwork << 3) + (lwork << 1);
60 if (cp < cbuf) abort(); /* rather die a horrible death than trash the memory */
62 } while (lwork & 0xffff0000);
65 register u_short sten = 10;
66 register u_short stmp;
67 register u_short swork = (u_short)lwork;
71 swork = (u_short) (swork/sten);
72 stmp = (u_short)(stmp - ((swork<<3) + (swork<<1)));
73 if (cp < cbuf) abort(); /* rather die a horrible death than trash the memory */
79 * Done that, now deal with the problem of the fraction. First
80 * determine the number of decimal places.
97 * If there's a fraction to deal with, do so.
109 * The scheme here is to multiply the
110 * fraction (0.1234...) by ten. This moves
111 * a junk of BCD into the units part.
112 * record that and iterate.
120 *cpend++ = (u_char)work.l_ui;
123 if (cpend > (cbuf + sizeof(cbuf))) abort(); /* rather die a horrible death than trash the memory */
129 if (work.l_uf & 0x80000000) {
130 register u_char *tp = cpend;
145 * We've now got the fraction in cbuf[], with cp pointing at
146 * the first character, cpend pointing past the last, and
147 * cpdec pointing at the first character past the decimal.
148 * Remove leading zeros, then format the number into the
165 *bp++ = (char)(*cp++ + '0'); /* ascii dependent? */