mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* util.c (ruby_strtod): Add support for Hexadecimal
floating-point expression [ruby-dev:40650] #2969 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f0be51c21
commit
9eb68d7c44
3 changed files with 52 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Mar 18 00:58:27 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* util.c (ruby_strtod): Add support for Hexadecimal
|
||||
floating-point expression [ruby-dev:40650] #2969
|
||||
|
||||
Thu Mar 18 00:00:58 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* lib/uri/common.rb (URI#{en,de}code_www_form_component):
|
||||
|
|
|
@ -1385,6 +1385,15 @@ class TestString < Test::Unit::TestCase
|
|||
assert_equal(5.9742e24, S("5.9742e24").to_f)
|
||||
assert_equal(98.6, S("98.6 degrees").to_f)
|
||||
assert_equal(0.0, S("degrees 100.0").to_f)
|
||||
assert_equal([ 0.0].pack('G'), [S(" 0.0").to_f].pack('G'))
|
||||
assert_equal([-0.0].pack('G'), [S("-0.0").to_f].pack('G'))
|
||||
assert_equal([ 0.0].pack('G'), [S(" 0x0p+0").to_f].pack('G'))
|
||||
assert_equal([-0.0].pack('G'), [S("-0x0p+0").to_f].pack('G'))
|
||||
assert_equal(1.0, S("0X1.P+0").to_f)
|
||||
assert_equal(1024.0, S("0x1p+10").to_f)
|
||||
assert_equal(0.0009765625, S("0x1p-10").to_f)
|
||||
assert_equal(2.6881171418161356e+43, S("0x1.3494a9b171bf5p+144").to_f)
|
||||
assert_equal(-3.720075976020836e-44, S("-0x1.a8c1f14e2af5dp-145").to_f)
|
||||
end
|
||||
|
||||
def test_to_i
|
||||
|
|
38
util.c
38
util.c
|
@ -2106,6 +2106,44 @@ ruby_strtod(const char *s00, char **se)
|
|||
}
|
||||
break2:
|
||||
if (*s == '0') {
|
||||
if (s[1] == 'x' || s[1] == 'X') {
|
||||
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
|
||||
s0 = ++s;
|
||||
adj = 0;
|
||||
|
||||
while (*++s && (s1 = strchr(hexdigit, *s))) {
|
||||
adj *= 16;
|
||||
adj += (s1 - hexdigit) & 15;
|
||||
}
|
||||
|
||||
if (*s == '.') {
|
||||
aadj = 1.;
|
||||
while (*++s && (s1 = strchr(hexdigit, *s))) {
|
||||
aadj /= 16;
|
||||
adj += aadj * ((s1 - hexdigit) & 15);
|
||||
}
|
||||
}
|
||||
|
||||
if (*s != 'P' && *s != 'p') {
|
||||
s = s0;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
dsign = 0x2C - *++s; /* +: 2B, -: 2D */
|
||||
if (abs(dsign) != 1) {
|
||||
s = s0;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
for (nd = 0, s++; (c = *s) >= '0' && c <= '9'; s++) {
|
||||
nd *= 10;
|
||||
nd += c;
|
||||
nd -= '0';
|
||||
}
|
||||
|
||||
dval(rv) = ldexp(adj, nd * dsign);
|
||||
goto ret;
|
||||
}
|
||||
nz0 = 1;
|
||||
while (*++s == '0') ;
|
||||
if (!*s)
|
||||
|
|
Loading…
Add table
Reference in a new issue