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: dad5ac56086f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fce4eaa25967
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on May 29, 2017

  1. Copy the full SHA
    3d30374 View commit details

Commits on Jun 5, 2017

  1. Merge pull request #4618 from cammellos/master

    Fix Float::INFINITY BigDecimal comparison
    headius authored Jun 5, 2017
    Copy the full SHA
    fce4eaa View commit details
Original file line number Diff line number Diff line change
@@ -508,7 +508,9 @@ private static RubyBigDecimal newInstance(Ruby runtime, IRubyObject recv, RubyFl
if (mathContext.getPrecision() > RubyFloat.DIG + 1) throw runtime.newArgumentError("precision too large");

double dblVal = arg.getDoubleValue();
if(Double.isInfinite(dblVal) || Double.isNaN(dblVal)) throw runtime.newFloatDomainError("NaN");

if(Double.isNaN(dblVal)) throw runtime.newFloatDomainError("NaN");
if(Double.isInfinite(dblVal)) return newInfinity(runtime, dblVal == Double.POSITIVE_INFINITY ? 1 : -1);

return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(dblVal, mathContext));
}
9 changes: 9 additions & 0 deletions spec/ruby/library/bigdecimal/gt_spec.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def > (other)

@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")

@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY

@nan = BigDecimal("NaN")
end

@@ -57,6 +61,11 @@ def > (other)
(@infinity > val).should == true
(val > @infinity_neg).should == true
(@infinity_neg > val).should == false

(val > @float_infinity).should == false
(@float_infinity > val).should == true
(val > @float_infinity_neg).should == true
(@float_infinity_neg > val).should == false
}
(@infinity > @infinity).should == false
(@infinity_neg > @infinity_neg).should == false
9 changes: 9 additions & 0 deletions spec/ruby/library/bigdecimal/gte_spec.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def >= (other)

@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")

@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY

@nan = BigDecimal("NaN")
end

@@ -61,6 +65,11 @@ def >= (other)
(@infinity >= val).should == true
(val >= @infinity_neg).should == true
(@infinity_neg >= val).should == false

(val >= @float_infinity).should == false
(@float_infinity >= val).should == true
(val >= @float_infinity_neg).should == true
(@float_infinity_neg >= val).should == false
}
(@infinity >= @infinity).should == true
(@infinity_neg >= @infinity_neg).should == true
9 changes: 9 additions & 0 deletions spec/ruby/library/bigdecimal/lt_spec.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def < (other)

@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")

@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY

@nan = BigDecimal("NaN")
end

@@ -55,6 +59,11 @@ def < (other)
(@infinity < val).should == false
(val < @infinity_neg).should == false
(@infinity_neg < val).should == true

(val < @float_infinity).should == true
(@float_infinity < val).should == false
(val < @float_infinity_neg).should == false
(@float_infinity_neg < val).should == true
}
(@infinity < @infinity).should == false
(@infinity_neg < @infinity_neg).should == false
9 changes: 9 additions & 0 deletions spec/ruby/library/bigdecimal/lte_spec.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def <= (other)

@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")

@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY

@nan = BigDecimal("NaN")
end

@@ -61,6 +65,11 @@ def <= (other)
(@infinity <= val).should == false
(val <= @infinity_neg).should == false
(@infinity_neg <= val).should == true

(val <= @float_infinity).should == true
(@float_infinity <= val).should == false
(val <= @float_infinity_neg).should == false
(@float_infinity_neg <= val).should == true
}
(@infinity <= @infinity).should == true
(@infinity_neg <= @infinity_neg).should == true