Fix Float#to_s specs to not depend on the platform representation of doubles

* AIX, Solaris, etc have a different binary representation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2019-04-01 20:35:10 +00:00
Родитель 321d72bdd6
Коммит c71c59feeb
1 изменённых файлов: 121 добавлений и 124 удалений

Просмотреть файл

@ -97,133 +97,130 @@ describe "Float#to_s" do
end
describe "matches" do
ruby_version_is "2.4" do # For unpack1
it "random examples in all ranges" do
# 50.times do
# bytes = (0...8).map { rand(256) }
# string = bytes.pack('C8')
# float = string.unpack('D').first
# puts " #{bytes.pack('C8').inspect}.unpack1('D').to_s.should == #{float.to_s.inspect}"
# end
it "random examples in all ranges" do
# 50.times do
# bytes = (0...8).map { rand(256) }
# string = bytes.pack('C8')
# float = string.unpack('D').first
# puts "#{'%.20g' % float}.to_s.should == #{float.to_s.inspect}"
# end
"\x97\x15\xC1| \xF5\x19\xAD".unpack1('D').to_s.should == "-1.9910613439044092e-91"
"\xBF\xF0\x14\xAD\xDF\x17q\xD1".unpack1('D').to_s.should == "-2.075408637901046e+84"
"\xDF\xBD\xC0\x89\xDA\x1F&$".unpack1('D').to_s.should == "1.5219626883645564e-134"
"|0<?a\xFB\xBFG".unpack1('D').to_s.should == "4.251130678455814e+37"
"U\xEE*\xB7\xF1\xB8\xE7\x18".unpack1('D').to_s.should == "1.0648588700899858e-188"
"\x15Y\xD1J\x80/7\xD0".unpack1('D').to_s.should == "-2.6847034291392176e+78"
"\x1D\x1E\xD2\x9A3)\xF5q".unpack1('D').to_s.should == "8.818842365424256e+240"
"M\xD0C\xA3\x19-\xE3\xE5".unpack1('D').to_s.should == "-6.365746090981858e+182"
"\xAFf\xFE\xF0$\x85\x01L".unpack1('D').to_s.should == "1.374692728674642e+58"
"'N\xB7\x12\xE0\xC8t\t".unpack1('D').to_s.should == "4.1254080603298014e-263"
"\xAFn\xF2x\x85\xB5\x15j".unpack1('D').to_s.should == "1.0635019031720867e+203"
"nQ\x95\xFA\xD9\xE3\xC5)".unpack1('D').to_s.should == "1.8641386367625094e-107"
"\xC2\x9A\xB1|/\xCAJM".unpack1('D').to_s.should == "2.204135837758401e+64"
"q n\xD8\x86\xF2\xA8D".unpack1('D').to_s.should == "5.890531214599543e+22"
"dmR\xC6\xB3\xF3\x95G".unpack1('D').to_s.should == "7.294790578028111e+36"
"6I\x0E)?E\xB5\xE1".unpack1('D').to_s.should == "-4.7847061687992665e+162"
"\xCD\xE0\xBBy\x9F\xD8\xE89".unpack1('D').to_s.should == "9.800091365433584e-30"
"\xB8\x98TN\x98\xEE\xC1\xF9".unpack1('D').to_s.should == "-3.178740061599073e+278"
"\x8F_\xFF\x15\x1F2\x17B".unpack1('D').to_s.should == "24906286463.84332"
"\x94\x18V\xC5&\xE6\xEAi".unpack1('D').to_s.should == "1.6471900588998988e+202"
"\xECq\xB1\x01\ai\xBD,".unpack1('D').to_s.should == "3.5248469410018065e-93"
"\x9C\xC6\x13pG\xDAx\x9A".unpack1('D').to_s.should == "-3.743306318201459e-181"
"\xEA7,gJ\xEE\x8E*".unpack1('D').to_s.should == "1.0789044330549825e-103"
"1\xD3\xF5K\x8D\xEF\xA7\r".unpack1('D').to_s.should == "7.011009309284311e-243"
"o\xB3\x02\xAF\x9D\xFC\r\xF6".unpack1('D').to_s.should == "-4.610585875652112e+260"
"&:x\x15\xFC3P\x01".unpack1('D').to_s.should == "2.362770515774595e-302"
"\xE6<C\xB8\x90\xF2\xCF\x90".unpack1('D').to_s.should == "-1.0535871178808475e-227"
"\x9Al\aB6's}".unpack1('D').to_s.should == "1.957205609213647e+296"
"+\v\x16\xFD\x19\x0E\x9B\x06".unpack1('D').to_s.should == "7.631200870990123e-277"
"\xEC\xF8~\xDA\xE7Tf\x92".unpack1('D').to_s.should == "-4.942358450191624e-220"
"\xE0\xA0\xC9\x906\xBDcI".unpack1('D').to_s.should == "3.521575588133954e+45"
"\xBD\xFD\xC9\xFD\rp\x02\x0F".unpack1('D').to_s.should == "2.2651682962118346e-236"
"\xE9\xA8\xAD\xC4\xF6u\xF7\x19".unpack1('D').to_s.should == "1.3803378872547194e-183"
"\"f\xED9\x17\xF0\xF1!".unpack1('D').to_s.should == "3.591307506787987e-145"
"\xE6\xF2\xB6\x9CFl\xB3O".unpack1('D').to_s.should == "8.785250953340842e+75"
"g\xFD\xEA\r~x\xBA\x9D".unpack1('D').to_s.should == "-1.7955908504285607e-165"
"\xE2\x84J\xC7\x00\n/\x06".unpack1('D').to_s.should == "6.839790344291208e-279"
"s\xFB\xA58x\xF1\xA9\xD9".unpack1('D').to_s.should == "-8.574967051032431e+123"
"\xE2\x9D\xBE\xE2\x10k{\xFC".unpack1('D').to_s.should == "-4.2751876153404507e+291"
"!z \xB4i4\x8C5".unpack1('D').to_s.should == "9.423078517655126e-51"
"!_\xEAp- 7R".unpack1('D').to_s.should == "1.1500944673871687e+88"
"\x03\xAD=\\\xCB >\xBB".unpack1('D').to_s.should == "-2.4921382721208654e-23"
"\x94\x01\xB1\x87\x10\x9B#\x88".unpack1('D').to_s.should == "-1.8555672851958583e-269"
"\x90H\xFF\\S\x01)\x89".unpack1('D').to_s.should == "-1.5509713490195968e-264"
"HW@\x13\x85&=)".unpack1('D').to_s.should == "4.848496966571536e-110"
"\x14\xDB\\\x10\x93\x9C\xD66".unpack1('D').to_s.should == "1.5842813502410472e-44"
"\x9D8p>\xFF\x9B[\xF3".unpack1('D').to_s.should == "-4.826061446912647e+247"
"c\x9D}\t]\xF9pg".unpack1('D').to_s.should == "1.8907034486212682e+190"
"\xA51\xC9WJ\xB5a^".unpack1('D').to_s.should == "4.422435231445608e+146"
"\x8BL\x90\xCB\xEARf\f".unpack1('D').to_s.should == "6.235963569982745e-249"
end
2.5540217314354050325e+163.to_s.should == "2.554021731435405e+163"
2.5492588360356597544e-172.to_s.should == "2.5492588360356598e-172"
1.742770260934704852e-82.to_s.should == "1.7427702609347049e-82"
6.2108093676180883209e-104.to_s.should == "6.210809367618088e-104"
-3.3448803488331067402e-143.to_s.should == "-3.3448803488331067e-143"
-2.2740074343500832557e-168.to_s.should == "-2.2740074343500833e-168"
7.0587971678048535732e+191.to_s.should == "7.058797167804854e+191"
-284438.88327586348169.to_s.should == "-284438.8832758635"
3.953272468476091301e+105.to_s.should == "3.9532724684760913e+105"
-3.6361359552959847853e+100.to_s.should == "-3.636135955295985e+100"
-1.3222325865575206185e-31.to_s.should == "-1.3222325865575206e-31"
1.1440138916932761366e+130.to_s.should == "1.1440138916932761e+130"
4.8750891560387561157e-286.to_s.should == "4.875089156038756e-286"
5.6101113356591453525e-257.to_s.should == "5.610111335659145e-257"
-3.829644279545809575e-100.to_s.should == "-3.8296442795458096e-100"
1.5342839401396406117e-194.to_s.should == "1.5342839401396406e-194"
2.2284972755169921402e-144.to_s.should == "2.228497275516992e-144"
2.1825655917065601737e-61.to_s.should == "2.1825655917065602e-61"
-2.6672271363524338322e-62.to_s.should == "-2.667227136352434e-62"
-1.9257995160119059415e+21.to_s.should == "-1.925799516011906e+21"
-8.9096732962887121718e-198.to_s.should == "-8.909673296288712e-198"
2.0202075376548644959e-90.to_s.should == "2.0202075376548645e-90"
-7.7341602581786258961e-266.to_s.should == "-7.734160258178626e-266"
3.5134482598733635046e+98.to_s.should == "3.5134482598733635e+98"
-2.124411722371029134e+154.to_s.should == "-2.124411722371029e+154"
-4.573908787355718687e+110.to_s.should == "-4.573908787355719e+110"
-1.9344425934170969879e-232.to_s.should == "-1.934442593417097e-232"
-1.3274227399979271095e+171.to_s.should == "-1.3274227399979271e+171"
9.3495270482104442383e-283.to_s.should == "9.349527048210444e-283"
-4.2046059371986483233e+307.to_s.should == "-4.2046059371986483e+307"
3.6133547278583543004e-117.to_s.should == "3.613354727858354e-117"
4.9247416523566613499e-08.to_s.should == "4.9247416523566613e-08"
1.6936145488250064007e-71.to_s.should == "1.6936145488250064e-71"
2.4455483206829433098e+96.to_s.should == "2.4455483206829433e+96"
7.9797449851436455384e+124.to_s.should == "7.979744985143646e+124"
-1.3873689634457876774e-129.to_s.should == "-1.3873689634457877e-129"
3.9761102037533483075e+284.to_s.should == "3.976110203753348e+284"
-4.2819791952139402486e-303.to_s.should == "-4.28197919521394e-303"
-5.7981017546689831298e-116.to_s.should == "-5.798101754668983e-116"
-3.953266497860534199e-28.to_s.should == "-3.953266497860534e-28"
-2.0659852720290440959e-243.to_s.should == "-2.065985272029044e-243"
8.9670488995878688018e-05.to_s.should == "8.967048899587869e-05"
-1.2317943708113061768e-98.to_s.should == "-1.2317943708113062e-98"
-3.8930768307633080463e+248.to_s.should == "-3.893076830763308e+248"
6.5854032671803925627e-239.to_s.should == "6.5854032671803926e-239"
4.6257022188980878952e+177.to_s.should == "4.625702218898088e+177"
-1.9397155125507235603e-187.to_s.should == "-1.9397155125507236e-187"
8.5752156951245705056e+117.to_s.should == "8.57521569512457e+117"
-2.4784875958162501671e-132.to_s.should == "-2.4784875958162502e-132"
-4.4125691841230058457e-203.to_s.should == "-4.412569184123006e-203"
end
it "random examples in human ranges" do
# 50.times do
# formatted = ''
# rand(1..3).times do
# formatted << rand(10).to_s
# end
# formatted << '.'
# rand(1..9).times do
# formatted << rand(10).to_s
# end
# float = formatted.to_f
# string = [float].pack('D')
# puts " #{string.inspect}.unpack1('D').to_s.should == #{float.to_s.inspect}"
# end
it "random examples in human ranges" do
# 50.times do
# formatted = ''
# rand(1..3).times do
# formatted << rand(10).to_s
# end
# formatted << '.'
# rand(1..9).times do
# formatted << rand(10).to_s
# end
# float = formatted.to_f
# puts "#{'%.20f' % float}.to_s.should == #{float.to_s.inspect}"
# end
";\x01M\x84\r\xF7M@".unpack1('D').to_s.should == "59.9301"
"\xAE\xD3HKe|\x8A@".unpack1('D').to_s.should == "847.54946"
"/\xDD$\x06\x81u8@".unpack1('D').to_s.should == "24.459"
"E\xD8\xF0\xF4JY\xF0?".unpack1('D').to_s.should == "1.0218"
"[\brP\xC2\xCC\x05@".unpack1('D').to_s.should == "2.72498"
"\xE6w\x9A\xCCx\xF6T@".unpack1('D').to_s.should == "83.851123"
"\xB4\xD4&\xC0C\xFD.@".unpack1('D').to_s.should == "15.494657521"
"\xCD\xCC\xCC\xCC\xCCLM@".unpack1('D').to_s.should == "58.6"
"\xA1\x84\x99\xB6\x7F\xE5\x13@".unpack1('D').to_s.should == "4.97412"
"\xD7\xA3p=\n\x9C\x80@".unpack1('D').to_s.should == "531.505"
"S\x96!\x8E\xF5\x0E\x8F@".unpack1('D').to_s.should == "993.8699"
"\xF1F\xE6\x91?\x18\xD7?".unpack1('D').to_s.should == "0.360855"
"=\n\xD7\xA3p=\x15@".unpack1('D').to_s.should == "5.31"
"\x90Ci\x147\xC74@".unpack1('D').to_s.should == "20.7781842"
"A\ft\xED\v\xE8\xB9?".unpack1('D').to_s.should == "0.101197"
"\x9A\x99\x99\x99\x999T@".unpack1('D').to_s.should == "80.9"
"\x00\x00\x00\x00\x00\x00\x1A@".unpack1('D').to_s.should == "6.5"
"\xD3J\xC6\xD6\x98\x8Es@".unpack1('D').to_s.should == "312.9123142"
"SQ\xE5I\fQ\x1E@".unpack1('D').to_s.should == "7.57914844"
"k]Q\xE7\xDDb\x1E@".unpack1('D').to_s.should == "7.59654962"
"\x1F\x85\xEBQ\xB8\xEAz@".unpack1('D').to_s.should == "430.67"
"\x00\x00\x00\x00\x00\x00\x14@".unpack1('D').to_s.should == "5.0"
"{\x14\xAEG\xE1\n}@".unpack1('D').to_s.should == "464.68"
"\x12\x83\xC0\xCA\xA1=V@".unpack1('D').to_s.should == "88.963"
"\x9Aw\x9C\xA2#y\e@".unpack1('D').to_s.should == "6.8683"
"(\x0F\v\xB5\xA6y\xFB?".unpack1('D').to_s.should == "1.7172"
"\xD5x\xE9&1H!@".unpack1('D').to_s.should == "8.641"
"w'Deh\x1Ab@".unpack1('D').to_s.should == "144.8252436"
":X\xFF\xE70_\x04@".unpack1('D').to_s.should == "2.54648"
"E4\xB2\x12\x90\xCA\x1E@".unpack1('D').to_s.should == "7.69781522"
"fffff\xAA\x80@".unpack1('D').to_s.should == "533.3"
"\xCD\x92\x005\xB5p:@".unpack1('D').to_s.should == "26.440265"
"\xBE\x1D<nS\x7F\x19@".unpack1('D').to_s.should == "6.3743417"
"R\xB8\x1E\x85\xEBYb@".unpack1('D').to_s.should == "146.81"
"\x02\x87\xAB^\xD9\xC0\xF4?".unpack1('D').to_s.should == "1.2970823"
"\x00\x00\x00\x00\x00\x00\"@".unpack1('D').to_s.should == "9.0"
"Zd;\xDFO3\x84@".unpack1('D').to_s.should == "646.414"
"\x9A\x99\x99\x99\x99\x99\t@".unpack1('D').to_s.should == "3.2"
"\xCD#\x7F0\xF0\xE5i@".unpack1('D').to_s.should == "207.18557"
"\xBE\x9F\x1A/\xDD$\xF2?".unpack1('D').to_s.should == "1.134"
"\xEE|?5^\xBA\xF3?".unpack1('D').to_s.should == "1.233"
"\xB4\xB7\xFE\xD7\x05\x03i@".unpack1('D').to_s.should == "200.094463346"
"N\x95\xD6|\xE8HG@".unpack1('D').to_s.should == "46.56959496"
"Y\x868\xD6\xC5-!@".unpack1('D').to_s.should == "8.5894"
"myE\xED\a;\x12@".unpack1('D').to_s.should == "4.557647426"
"\xA7s\xEAo\xAE\x96B@".unpack1('D').to_s.should == "37.1771984"
"\x14\x7Fo.\x99\x11|@".unpack1('D').to_s.should == "449.0998978"
"\xB2\x9EZ}u\x89;@".unpack1('D').to_s.should == "27.536949"
"\xD7\xA3p=\nwY@".unpack1('D').to_s.should == "101.86"
"\xF3\xE6p\xAD\xF6\xC3x@".unpack1('D').to_s.should == "396.247724"
end
5.17869899999999994122.to_s.should == "5.178699"
905.62695729999995819526.to_s.should == "905.6269573"
62.75999999999999801048.to_s.should == "62.76"
6.93856795800000014651.to_s.should == "6.938567958"
4.95999999999999996447.to_s.should == "4.96"
32.77993899999999882766.to_s.should == "32.779939"
544.12756779999995160324.to_s.should == "544.1275678"
66.25801119999999855281.to_s.should == "66.2580112"
7.90000000000000035527.to_s.should == "7.9"
5.93100000000000004974.to_s.should == "5.931"
5.21229313600000043749.to_s.should == "5.212293136"
503.44173809000000119340.to_s.should == "503.44173809"
79.26000000000000511591.to_s.should == "79.26"
8.51524999999999998579.to_s.should == "8.51525"
174.00000000000000000000.to_s.should == "174.0"
50.39580000000000126192.to_s.should == "50.3958"
35.28999999999999914735.to_s.should == "35.29"
5.43136675399999990788.to_s.should == "5.431366754"
654.07680000000004838512.to_s.should == "654.0768"
6.07423700000000010846.to_s.should == "6.074237"
102.25779799999999397642.to_s.should == "102.257798"
5.08129999999999970584.to_s.should == "5.0813"
6.00000000000000000000.to_s.should == "6.0"
8.30000000000000071054.to_s.should == "8.3"
32.68345999999999662577.to_s.should == "32.68346"
581.11170000000004165486.to_s.should == "581.1117"
76.31342999999999676675.to_s.should == "76.31343"
438.30826000000001840817.to_s.should == "438.30826"
482.06631994000002805478.to_s.should == "482.06631994"
55.92721026899999969828.to_s.should == "55.927210269"
4.00000000000000000000.to_s.should == "4.0"
55.86693999999999959982.to_s.should == "55.86694"
787.98299999999994724931.to_s.should == "787.983"
5.73810511000000023074.to_s.should == "5.73810511"
74.51926810000000500622.to_s.should == "74.5192681"
892.89999999999997726263.to_s.should == "892.9"
68.27299999999999613465.to_s.should == "68.273"
904.10000000000002273737.to_s.should == "904.1"
5.23200000000000020606.to_s.should == "5.232"
4.09628000000000014325.to_s.should == "4.09628"
46.05152633699999853434.to_s.should == "46.051526337"
142.12884990599999923688.to_s.should == "142.128849906"
3.83057023500000015659.to_s.should == "3.830570235"
11.81684594699999912848.to_s.should == "11.816845947"
80.50000000000000000000.to_s.should == "80.5"
382.18215010000000120272.to_s.should == "382.1821501"
55.38444606899999911320.to_s.should == "55.384446069"
5.78000000000000024869.to_s.should == "5.78"
2.88244999999999995666.to_s.should == "2.88245"
43.27709999999999723741.to_s.should == "43.2771"
end
it "random values from divisions" do