5 * strtod implementation.
6 * author: Yasuhiro Matsumoto (@mattn)
7 * license: public domain
11 The original code can be found in https://github.com/mattn/strtod
13 I modified the routine for mruby:
15 * renamed the function `vim_strtod` -> `mrb_read_float`
19 My modifications in this file are also placed in the public domain.
21 Matz (Yukihiro Matsumoto)
28 mrb_read_float(const char *str
, char **endp
, double *fp
)
47 d
= (double)(*p
++ - '0');
48 while (*p
&& ISDIGIT(*p
)) {
49 d
= d
* 10.0 + (double)(*p
- '0');
65 while (*p
&& ISDIGIT(*p
)) {
66 f
+= base
* (*p
- '0');
75 /* exponential part */
76 if ((*p
== 'E') || (*p
== 'e')) {
92 e
= (int)(*p
++ - '0');
93 for (; *p
&& ISDIGIT(*p
); p
++) {
95 e
= e
* 10 + (*p
- '0');
99 else if (!ISDIGIT(*(a
-1))) {
104 d
*= pow(10.0, (double)e
);
107 else if (p
> str
&& !ISDIGIT(*(p
-1))) {
113 if (endp
) *endp
= (char*)a
;
114 if (str
== a
) return FALSE
;