From c71c59feeb8edd975cc49c718dec8319e22ee2a4 Mon Sep 17 00:00:00 2001 From: eregon Date: Mon, 1 Apr 2019 20:35:10 +0000 Subject: [PATCH] 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 --- spec/ruby/core/float/to_s_spec.rb | 245 +++++++++++++++--------------- 1 file changed, 121 insertions(+), 124 deletions(-) diff --git a/spec/ruby/core/float/to_s_spec.rb b/spec/ruby/core/float/to_s_spec.rb index 127132b567..db375bfc0e 100644 --- a/spec/ruby/core/float/to_s_spec.rb +++ b/spec/ruby/core/float/to_s_spec.rb @@ -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\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