diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-01-06 15:47:19 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-01-06 15:52:39 +0900 |
| commit | ccf28775b896e7cf772657eacd8727de25c3a0f4 (patch) | |
| tree | 442be2b2e6b5e51abc4a7996c022c131e1f9d6d1 /src/string.c | |
| parent | 2532e625edc2457447369e36e2ecf7882d872ef9 (diff) | |
| download | mruby-ccf28775b896e7cf772657eacd8727de25c3a0f4.tar.gz mruby-ccf28775b896e7cf772657eacd8727de25c3a0f4.zip | |
Fix `mrb_str_len_to_dbl` to support Hexadecimal like `0x10`.
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c index 15e52fb3c..7b6a11a6f 100644 --- a/src/string.c +++ b/src/string.c @@ -2503,8 +2503,15 @@ mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck) while (ISSPACE(*s)) s++; p = s; - if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { - return 0.0; + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + mrb_value x; + + x = mrb_str_len_to_inum(mrb, p, pend-p, 0, badcheck); + if (mrb_fixnum_p(x)) + d = (double)mrb_fixnum(x); + else /* if (mrb_float_p(x)) */ + d = mrb_float(x); + return d; } while (p < pend) { if (!*p) { |
