Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
Created November 15, 2015 01:56
Show Gist options
  • Save joshuaflanagan/44a8c4f3d8cf53b24e60 to your computer and use it in GitHub Desktop.
Save joshuaflanagan/44a8c4f3d8cf53b24e60 to your computer and use it in GitHub Desktop.
BigDecimal does not Marshal round trip in ruby 2.1/2.2 (did in 1.9.3)
# Ruby 2.1.2
2.1.2 :173 > x = BigDecimal.new(1.0, 1)
=> #<BigDecimal:7ffcee09bb98,'0.1E1',9(27)>
2.1.2 :174 > y = Marshal.load Marshal.dump x
=> #<BigDecimal:7ffcec5d9ee0,'0.1E1',9(18)>
2.1.2 :175 > x == y
=> true
2.1.2 :176 > Marshal.dump(x) == Marshal.dump(y)
=> false
2.1.2 :177 > x.precs
=> [9, 27]
2.1.2 :178 > y.precs
=> [9, 18]
# ruby 1.9.3
1.9.3-p551 :044 > x = BigDecimal.new(1,1)
=> #<BigDecimal:7fbeccce7600,'0.1E1',9(36)>
1.9.3-p551 :045 > y = Marshal.load Marshal.dump x
=> #<BigDecimal:7fbecc8d8aa0,'0.1E1',9(36)>
1.9.3-p551 :046 > x == y
=> true
1.9.3-p551 :047 > Marshal.dump(x) == Marshal.dump(y)
=> true
1.9.3-p551 :048 > x.precs
=> [9, 36]
1.9.3-p551 :049 > y.precs
=> [9, 36]
@joshuaflanagan
Copy link
Author

Is this a bug? It feels like the unmarshalled value (y) in 2.1 could have different behavior than its original value (x), since the "maximum number of significant digits" (from precs documentation) changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment