Skip to content

Fix Float#to_d of bigdecimal/util#7652

Merged
headius merged 3 commits intojruby:masterfrom
k77ch7:ruby-3.1-fix-float-to_d
Feb 15, 2023
Merged

Fix Float#to_d of bigdecimal/util#7652
headius merged 3 commits intojruby:masterfrom
k77ch7:ruby-3.1-fix-float-to_d

Conversation

@k77ch7
Copy link
Contributor

@k77ch7 k77ch7 commented Feb 11, 2023

This change uses BigDecimal(string) instead of BigDecimal(double) to generate correct BigDecimal value and to avoid precision error.

Fixes #7650

This change uses BigDecimal(string) instead of BigDecimal(double) to generate correct BigDecimal value and to avoid precision error.

Fixes jruby#7650
if (res != null) return res;

return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(arg.getDoubleValue(), mathContext));
return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(arg.inspect().asJavaString(), mathContext));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can just be arg.toString(), avoiding the intermediate RubyString object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@headius thanks

@headius headius added this to the JRuby 9.4.2.0 milestone Feb 12, 2023
@headius
Copy link
Member

headius commented Feb 15, 2023

I want there to be a better way to do this without the intermediate string, but this seems to be the best we can do with Java's BigDecimal for now. Merging. Thank you!

@headius headius merged commit 0588105 into jruby:master Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigDecimal arithmetic regression [jruby-9.4]

2 participants