Skip to content

Commit

Permalink
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/ruby/core/fixnum/minus_spec.rb
Original file line number Diff line number Diff line change
@@ -9,6 +9,14 @@
(2_560_496 - bignum_value).should == -9223372036852215312
end

it "returns a Bignum only if the result is too large to be a Fixnum" do
(5 - 10).should be_an_instance_of Fixnum
(1 - bignum_value).should be_an_instance_of Bignum

bignum_zero = bignum_value.coerce(0).first
(1 - bignum_zero).should be_an_instance_of Fixnum
end

it "raises a TypeError when given a non-Integer" do
lambda {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
5 changes: 4 additions & 1 deletion vm/builtin/fixnum.cpp
Original file line number Diff line number Diff line change
@@ -56,7 +56,10 @@ namespace rubinius {
}

Integer* Fixnum::sub(STATE, Bignum* other) {
return as<Bignum>(other->neg(state))->add(state, this);
Integer* neg = other->neg(state);
if (Bignum* bneg = try_as<Bignum>(neg))
return bneg->add(state, this);
return as<Fixnum>(neg)->add(state, this);
}

Float* Fixnum::sub(STATE, Float* other) {

0 comments on commit 0318b9a

Please sign in to comment.