flt
flt copied to clipboard
Conversion to/from BigDecimal doesn't work within Spork
I have been picking at this issue on and off for weeks, but hadn't been able to make any progress on it until now. I have a bunch of RSpec specs that fail only when I'm using Spork, all with the same error message for the same line of code:
Flt::DecNum can't be coerced into BigDecimal
I followed the instructions in your README just now and added a file to ./config/initializers/flt.rb
with these conversion functions in it:
DecNum.context.define_conversion_from(BigDecimal) do |x, context|
DecNum(x.to_s)
end
DecNum.context.define_conversion_to(BigDecimal) do |x|
BigDecimal.new(x.to_s)
end
I still get the error though. The mysterious thing to me is that even before I wrote that initializer, the specs all pass without Spork. It's not like I need to use Spork (obviously I've been okay without it for several weeks), but it is pretty annoying having such an arbitrary bug. Can you lend any insight into what's happening here, why it works outside of Spork, and what I can do to fix it?
I am seeing this too, but instead of only within Spork, I see it only on Linux (not on OSX) Doing an operation such as
DecNum('15.47928602931972642303350358') * BigDecimal('500.00000000000000000000')
triggers the error.
This is very similar (or equivalent) to the issue reported in the 'finance' gem.
Would appreciate any help or ideas regarding this.
So, for me at least it seems like a Ruby build version problem. Upgraded from 1.9.3-p125 to 1.9.3-p194 and it went away. Worth giving a shot.