Created
July 27, 2021 21:55
-
-
Save casperisfine/f3f7b30d0ce4b4f41bc19eae097143b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "bigdecimal/util" | |
# Ref: https://github.com/ruby/ruby/commit/e1424c35012ccf1f3822c9046081b225aef4142e | |
# Ref: https://github.com/ruby/bigdecimal/issues/70 | |
# Ruby 3.0 changed the default precision used when calling `Float#to_d` from 15 to 16. | |
# It causes a whole lot of issues. I'm trying to figure out what can be done about it | |
# but in the meantime the only solution I see is to revert it back to 2.x behavior. | |
if RUBY_VERSION >= "3.0" | |
class Float | |
def to_d(precision = Float::DIG) | |
BigDecimal(self, precision) | |
end | |
end | |
end |
I believe the issue still exists in ruby v3.1.2
I don't think so, we were able to remove the patch when we upgraded to 3.1.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haha, I just had to write this myself, thank you for posting it. I work at a rails company now moving to ruby3.
I ended up stumbling here from rails/rails#42098 (comment)
I believe the issue still exists in ruby v3.1.2
thanks again @casperisfine