Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 77f76600c5a8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f0f73eab4d61
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Sep 22, 2016

  1. Bring BigMath::log behaviour closer to MRI

    Especially for a Rational, high precision use-case
    
    Fixes #4158
    shirshendu authored and headius committed Sep 22, 2016
    Copy the full SHA
    68552a3 View commit details
  2. 3
    Copy the full SHA
    84a5f78 View commit details
  3. Tag failing BigMath.log spec.

    headius committed Sep 22, 2016
    Copy the full SHA
    f0f73ea View commit details
Showing with 16 additions and 2 deletions.
  1. +5 −2 core/src/main/ruby/jruby/bigdecimal.rb
  2. +10 −0 spec/ruby/library/bigmath/log_spec.rb
  3. +1 −0 spec/truffle/tags/library/bigmath/log_tags.txt
7 changes: 5 additions & 2 deletions core/src/main/ruby/jruby/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ def log(x, prec)
return BigDecimal::INFINITY if x.infinite?
return BigDecimal::NAN if x.nan?
end
x = x.is_a?(Rational) ? x.to_d(Float::DIG) : x.to_d
x = x.is_a?(Rational) ? x.to_d(prec) : x.to_d
return BigDecimal::INFINITY if x.infinite?
return BigDecimal::NAN if x.nan?

@@ -59,9 +59,12 @@ def log(x, prec)
element_exponent = series_element.exponent
remaining_precision = n - (sum_exponent - element_exponent).abs
break if remaining_precision < 0
if remaining_precision < rmpd_double_figures
remaining_precision = rmpd_double_figures
end
z = z.mult(z2, n)
i += 2
series_element = z.div(i, n)
series_element = z.div(i, remaining_precision)
series_sum += series_element
end

10 changes: 10 additions & 0 deletions spec/ruby/library/bigmath/log_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'bigdecimal'

describe "BigDecimal#abs" do
it "handles high-precision Rational arguments" do
result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0')
r = Rational(1_234_567_890, 987_654_321)
BigMath.log(r, 50).should == result
end
end
1 change: 1 addition & 0 deletions spec/truffle/tags/library/bigmath/log_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:BigDecimal#abs handles high-precision Rational arguments