diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-01 04:32:43 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-01 04:32:43 +0000 |
commit | 4d399f12d4354c17bbb1ea2b12de4c11c6ac03ff (patch) | |
tree | 996a9f52ab0cd10d044d0949116c276627caad02 /test | |
parent | 2067e4eb30eb78b36c252baff319c6d581700460 (diff) |
* 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
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_float.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index c18e4f0422..3e5b1177c0 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -87,6 +87,18 @@ class TestFloat < Test::Unit::TestCase assert_raise(ArgumentError){Float("1__1")} # add expected behaviour here. assert_equal(10, Float("1_0")) + + assert_equal([ 0.0].pack('G'), [Float(" 0x0p+0").to_f].pack('G')) + assert_equal([-0.0].pack('G'), [Float("-0x0p+0").to_f].pack('G')) + assert_equal(255.0, Float("0Xff")) + assert_equal(255.5, Float("0Xff.8")) + assert_equal(1.0, Float("0X1.P+0")) + assert_equal(1024.0, Float("0x1p10")) + assert_equal(1024.0, Float("0x1p+10")) + assert_equal(0.0009765625, Float("0x1p-10")) + assert_equal(2.6881171418161356e+43, Float("0x1.3494a9b171bf5p+144")) + assert_equal(-3.720075976020836e-44, Float("-0x1.a8c1f14e2af5dp-145")) + end def test_divmod diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 9dd3ea90ce..c5b86fa177 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1398,7 +1398,10 @@ class TestString < Test::Unit::TestCase 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(255.0, S("0Xff").to_f) + assert_equal(255.5, S("0Xff.8").to_f) assert_equal(1.0, S("0X1.P+0").to_f) + assert_equal(1024.0, S("0x1p10").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) |