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
)
48 d
= (double)(*p
++ - '0');
49 while (*p
&& ISDIGIT(*p
)) {
50 d
= d
* 10.0 + (double)(*p
- '0');
67 while (*p
&& ISDIGIT(*p
)) {
68 f
+= base
* (*p
- '0');
78 /* exponential part */
79 if ((*p
== 'E') || (*p
== 'e')) {
95 e
= (int)(*p
++ - '0');
96 for (; *p
&& ISDIGIT(*p
); p
++) {
98 e
= e
* 10 + (*p
- '0');
102 else if (!ISDIGIT(*(a
-1))) {
107 d
*= pow(10.0, (double)e
);
110 else if (p
> str
&& !ISDIGIT(*(p
-1))) {
116 if (endp
) *endp
= (char*)a
;
117 if (str
== a
) return FALSE
;