4 * dofptoa - do the grunge work to convert an fp number to ascii
9 #include "lib_strbuf.h"
10 #include "ntp_string.h"
11 #include "ntp_stdlib.h"
21 register u_char
*cp
, *cpend
;
30 * Get a string buffer before starting
37 memset((char *)cbuf
, 0, sizeof cbuf
);
40 * Set the pointers to point at the first
41 * decimal place. Get a local copy of the value.
43 cp
= cpend
= &cbuf
[5];
47 * If we have to, decode the integral part
49 if (!(val
& 0xffff0000))
52 register u_short sv
= (u_short
)(val
>> 16);
54 register u_short ten
= 10;
58 sv
= (u_short
) (sv
/ten
);
59 *(--cp
) = (u_char
)(tmp
- ((sv
<<3) + (sv
<<1)));
64 * Figure out how much of the fraction to do
67 dec
= (short)(ndec
+ 3);
82 val
= (val
<< 3) + (val
<< 1);
83 *cpend
++ = (u_char
)(val
>> 16);
101 * Remove leading zeroes if necessary
103 while (cp
< (cpdec
-1) && *cp
== 0)
107 * Copy it into the buffer, asciizing as we go.
116 *bp
++ = (char)(*cp
++ + '0');