Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/std/big/big_rational_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ describe BigRational do
r.to_s(36).should eq("4woiz/9b3djm")
end

it "#to_i" do
br(10, 3).to_i.should eq(3)
br(90, 3).to_i.should eq(30)
br(1, 98).to_i.should eq(0)
br(-10, 3).to_i.should eq(-3)
expect_raises(OverflowError) { br(Int64::MAX, 1).to_i }
end

it "#to_f64" do
r = br(10, 3)
f = 10.to_f64 / 3.to_f64
Expand Down
4 changes: 4 additions & 0 deletions src/big/big_rational.cr
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ struct BigRational < Number
to_f64!
end

def to_i : Int32
to_i32
end

delegate to_i8, to_i16, to_i32, to_i64, to_u8, to_u16, to_u32, to_u64, to: to_f64

# Returns `self`.
Expand Down