1 /* $NetBSD: atolfp.c,v 1.1.1.1 2009/12/13 16:55:01 kardel Exp $ */
4 * atolfp - convert an ascii string to an l_fp number
10 #include "ntp_string.h"
11 #include "ntp_assert.h"
16 static u_long ten_to_the_n
[10] = {
36 register const char *cp
;
37 register u_long dec_i
;
38 register u_long dec_f
;
42 static const char *digits
= "0123456789";
44 NTP_REQUIRE(str
!= NULL
);
52 * We understand numbers of the form:
54 * [spaces][-|+][digits][.][digits][spaces|\n|\0]
56 while (isspace((unsigned char)*cp
))
67 if (*cp
!= '.' && !isdigit((unsigned char)*cp
))
70 while (*cp
!= '\0' && (ind
= strchr(digits
, *cp
)) != NULL
) {
71 dec_i
= (dec_i
<< 3) + (dec_i
<< 1); /* multiply by 10 */
72 dec_i
+= (ind
- digits
);
76 if (*cp
!= '\0' && !isspace((unsigned char)*cp
)) {
80 while (ndec
< 9 && *cp
!= '\0'
81 && (ind
= strchr(digits
, *cp
)) != NULL
) {
83 dec_f
= (dec_f
<< 3) + (dec_f
<< 1); /* *10 */
84 dec_f
+= (ind
- digits
);
88 while (isdigit((unsigned char)*cp
))
91 if (*cp
!= '\0' && !isspace((unsigned char)*cp
))
98 register u_long ten_fact
;
100 ten_fact
= ten_to_the_n
[ndec
];
106 if (dec_f
>= ten_fact
) {
112 if ((dec_f
<< 1) > ten_fact
)