Fix `mrb_str_len_to_dbl` to support Hexadecimal like `0x10`.
MODIFY
mrbgems/mruby-kernel-ext/test/kernel.rb
mrbgems/mruby-kernel-ext/test/kernel.rb
@@ -80,6 +80,7 @@ assert('Kernel#Float') do
assert_operator(12.34, :eql?, Float('1_2.3_4'))
assert_operator(0.9, :eql?, Float('.9'))
assert_operator(0.9, :eql?, Float(" \t\r\n\f\v.9 \t\r\n\f\v"))
+ assert_operator(16.0, :eql?, Float("0x10"))
assert_raise(TypeError) { Float(nil) }
assert_raise(ArgumentError) { Float("1. 5") }
assert_raise(ArgumentError) { Float("1.5a") }

MODIFY
src/string.c
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) {

Fix `mrb_str_len_to_dbl` to support Hexadecimal like `0x10`.