Merge pull request #6289 from dearblue/orphan-block
[mruby.git] / src / readnum.c
blob3c459d068dbcbcd4bae915b15c2514252e867406
1 /* this file defines obsolete functions: mrb_int_read() and mrb_float_read() */
2 /* use mrb_read_int() and mrb_read_float() instead */
4 #include <mruby.h>
5 #include <mruby/numeric.h>
6 #include <errno.h>
8 /* mrb_int_read(): read mrb_int from a string (base 10 only) */
9 /* const char *p - string to read */
10 /* const char *e - end of string */
11 /* char **endp - end of parsed integer */
13 /* if integer overflows, errno will be set to ERANGE */
14 /* also endp will be set to NULL on overflow */
15 MRB_API mrb_int
16 mrb_int_read(const char *p, const char *e, char **endp)
18 mrb_int n;
20 if (!mrb_read_int(p, e, endp, &n)) {
21 if (endp) *endp = NULL;
22 errno = ERANGE;
23 return MRB_INT_MAX;
25 if (endp) *endp = (char*)p;
26 return n;
29 #ifndef MRB_NO_FLOAT
30 //#include <string.h>
31 //#include <math.h>
33 MRB_API double
34 mrb_float_read(const char *str, char **endp)
36 double d;
38 if (!mrb_read_float(str, endp, &d)) {
39 errno = ERANGE;
41 return d;
43 #endif