Skip to content

Fix BigDecimal(0, NAN and INFINITY) to return always same object#7768

Merged
enebo merged 2 commits intojruby:masterfrom
k77ch7:ruby-3.1-fix-bigdeciaml-zero-nan-infinity
Apr 29, 2023
Merged

Fix BigDecimal(0, NAN and INFINITY) to return always same object#7768
enebo merged 2 commits intojruby:masterfrom
k77ch7:ruby-3.1-fix-bigdeciaml-zero-nan-infinity

Conversation

@k77ch7
Copy link
Contributor

@k77ch7 k77ch7 commented Apr 23, 2023

The following tests will pass.

  • test_BigDecimal_with_float in test/mri/bigdecimal/test_bigdecimal.rb

@ahorek ahorek added this to the JRuby 9.4.3.0 milestone Apr 23, 2023
Comment on lines 130 to 135
private static RubyBigDecimal POSITIVE_ZERO;
private static RubyBigDecimal NEGATIVE_ZERO;
private static RubyBigDecimal POSITIVE_INFINITY;
private static RubyBigDecimal NEGATIVE_INFINITY;
private static RubyBigDecimal NAN;

Copy link
Member

Choose a reason for hiding this comment

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

These cannot be static fields because:

  1. people with multiple Ruby runtimes in a single JVM will get values from other runtimes and bad things happen
  2. can potentially leak entire runtime since Runtime pins the entire system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@enebo thanks for your review. i updated my PR using setConstant and setConstantVisibility.

Copy link
Member

Choose a reason for hiding this comment

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

If we notice a performance issue with constant table lookup here we can promote these to ordinary fields in some per-runtime Java object but this looks fine.

k77ch7 added 2 commits April 28, 2023 22:54
The following tests will pass.
 * test_BigDecimal_with_float in  test/mri/bigdecimal/test_bigdecimal.rb
@k77ch7 k77ch7 force-pushed the ruby-3.1-fix-bigdeciaml-zero-nan-infinity branch from 776d5b6 to 70e07d2 Compare April 29, 2023 06:19
@enebo enebo merged commit 5a8925e into jruby:master Apr 29, 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.

3 participants