2 * atolfp - convert an ascii string to an l_fp number
9 #include "ntp_string.h"
10 #include "ntp_assert.h"
15 static u_long ten_to_the_n[10] = {
35 register const char *cp;
36 register u_long dec_i;
37 register u_long dec_f;
41 static const char *digits = "0123456789";
43 NTP_REQUIRE(str != NULL);
51 * We understand numbers of the form:
53 * [spaces][-|+][digits][.][digits][spaces|\n|\0]
55 while (isspace((unsigned char)*cp))
66 if (*cp != '.' && !isdigit((unsigned char)*cp))
69 while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
70 dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */
71 dec_i += (ind - digits);
75 if (*cp != '\0' && !isspace((unsigned char)*cp)) {
79 while (ndec < 9 && *cp != '\0'
80 && (ind = strchr(digits, *cp)) != NULL) {
82 dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */
83 dec_f += (ind - digits);
87 while (isdigit((unsigned char)*cp))
90 if (*cp != '\0' && !isspace((unsigned char)*cp))
97 register u_long ten_fact;
99 ten_fact = ten_to_the_n[ndec];
105 if (dec_f >= ten_fact) {
111 if ((dec_f << 1) > ten_fact)