Marshal's dump output for Floats is different from MRI
------------------------------------------------------
Key: JRUBY-4335
URL: http://jira.codehaus.org/browse/JRUBY-4335
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules, RubySpec
Affects Versions: JRuby 1.4
Reporter: Vladimir Sizikov
This leads to the following rubyspec error:
{noformat}
Marshal.dump dumps a Float 8323434.342 FAILED
Expected "\004\bf\0208323434.342"
to equal "\004\bf\0328323434.3420000002\000S\370"
{noformat}
Essentially, MRI format has been extended to save mantissa in the produced data
as well.
For the background of the change, take a look at the following mail discussion:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/69518
Also, here are some tests that triggered the change in MRI:
{code}
[1.5, 4.0/3.0].each { |a|
ma = Marshal.dump(a)
b = Marshal.load(ma)
if a == b
# puts "Everything is working fine for #{a}"
else
puts "PROBLEM: a is #{a}, b is #{b}, and ma is #{ma.dump}"
end
}
[[1,2,3,4], [81, 2, 118, 3146]].each { |w,x,y,z|
a = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f))
ma = Marshal.dump(a)
b = Marshal.load(ma)
if a == b
# puts "Everything is working fine for #{a}"
else
puts "PROBLEM: a is #{a}, b is #{b}, and ma is #{ma.dump}"
end
}
100000.times {
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))
ma = Marshal.dump(a)
b = Marshal.load(ma)
if a == b
# puts "Everything is working fine for #{a}"
else
puts "PROBLEM: a is #{a}, b is #{b}, and ma is #{ma.dump}"
puts "w is #{w}, x is #{x}, y is #{y}, z is #{z}"
end
}
5000000.times {
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))
ma = Marshal.dump(a)
b = Marshal.load(ma)
if a == b
# puts "Everything is working fine for #{a}"
else
puts "PROBLEM#4: a is #{a}, b is #{b}, and ma is #{ma.dump}"
puts "w is #{w}, x is #{x}, y is #{y}, z is #{z}"
end
}
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email