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

Commits on Sep 27, 2014

  1. Try to coerce Complex with only real part.

    This closes #3142.
    Benny committed Sep 27, 2014
    Copy the full SHA
    90dbe7c View commit details

Commits on Sep 28, 2014

  1. Copy the full SHA
    067d546 View commit details
  2. Merge pull request #3143 from Benny1992/master

    Coerce Complex with only real part
    jc00ke committed Sep 28, 2014
    Copy the full SHA
    093f029 View commit details
Showing with 9 additions and 1 deletion.
  1. +5 −1 kernel/bootstrap/type.rb
  2. +4 −0 spec/ruby/core/kernel/Float_spec.rb
6 changes: 5 additions & 1 deletion kernel/bootstrap/type.rb
Original file line number Diff line number Diff line change
@@ -111,7 +111,11 @@ def self.coerce_object_to_float(obj)
when nil
raise TypeError, "can't convert nil into Float"
when Complex
raise RangeError, "can't convert #{obj} into Float"
if obj.respond_to?(:imag) && obj.imag.equal?(0)
coerce_to obj, Float, :to_f
else
raise RangeError, "can't convert #{obj} into Float"
end
else
coerce_to obj, Float, :to_f
end
4 changes: 4 additions & 0 deletions spec/ruby/core/kernel/Float_spec.rb
Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@
@object.send(:Float, 1).should == 1.0
end

it "returns a Float for Complex with only a real part" do
@object.send(:Float, Complex(1)).should == 1.0
end

it "returns a Float for Bignums" do
@object.send(:Float, 1000000000000).should == 1000000000000.0
end