From 4d399f12d4354c17bbb1ea2b12de4c11c6ac03ff Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 1 Apr 2010 04:32:43 +0000 Subject: * object.c (rb_cstr_to_dbl): return 0.0 if hexadecimal and baccheck is FALSE: Float("0x1p+0") works, but "0x1p+0".to_f doesn't. [ruby-dev:40650] * util.c (ruby_strtod): allow hexdecimal integers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index cdcd287016..4fc4b6a759 100644 --- a/object.c +++ b/object.c @@ -2246,6 +2246,11 @@ rb_cstr_to_dbl(const char *p, int badcheck) if (!p) return 0.0; q = p; while (ISSPACE(*p)) p++; + + if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + return 0.0; + } + d = strtod(p, &end); if (errno == ERANGE) { OutOfRange(); @@ -2284,6 +2289,11 @@ rb_cstr_to_dbl(const char *p, int badcheck) } *n = '\0'; p = buf; + + if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + return 0.0; + } + d = strtod(p, &end); if (errno == ERANGE) { OutOfRange(); -- cgit v1.2.1