From: ts Date: 2003-04-19T22:28:49+09:00 Subject: Re: Roundoff problem with Float and Marshal >>>>> "R" == Rudi Cilibrasi writes: R> This is a tricky problem. I have rewritten my patch in a way that I hope R> is endian-independent, and furthermore allows you to load and save exactly R> across any IEEE754 system, whether big or little endian floats. The test was pigeon% cat b.rb #!./ruby -v io = if ARGV.size != 0 args = true File.new('tt') else args = false File.new('tt', 'w') end srand(1256457) 32.times do |cnt| w = rand(111111111) x = rand(222222223) y = rand(33333333334) z = rand(311414313) a = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f)) if args ma = Marshal.load(io) if a != ma puts "Error #{cnt} : #{a} -- #{ma}" end else ma = Marshal.dump(a, io) end end pigeon% pigeon% ./b.rb ruby 1.8.0 (2003-04-18) [i686-linux] pigeon% pigeon% ./b.rb 1 ruby 1.8.0 (2003-04-18) [i686-linux] pigeon% nasun% ./b.rb 1 ruby 1.8.0 (2003-04-18) [sparc-solaris2.8] Error 25 : 253341198.872703 -- 253341198.872703 -- 5.96046447753906e-08 nasun% `32.times' was just to have the first error Guy Decoux