Skip to content

Commit

Permalink
Add BigRational#to_big_r (#11462)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Nov 18, 2021
1 parent c722e85 commit a9ee264
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/std/big/big_rational_spec.cr
Expand Up @@ -96,6 +96,11 @@ describe BigRational do
r.to_big_f.should be_close(f, 0.001)
end

it "#to_big_r" do
r = br(10, 3)
r.to_big_r.should eq(r)
end

it "Int#to_big_r" do
3.to_big_r.should eq(br(3, 1))
end
Expand Down
11 changes: 11 additions & 0 deletions src/big/big_rational.cr
Expand Up @@ -233,6 +233,17 @@ struct BigRational < Number

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

# Returns `self`.
#
# ```
# require "big"
#
# BigRational.new(4, 5).to_big_r # => 4/5
# ```
def to_big_r : BigRational
self
end

def to_big_f : BigFloat
BigFloat.new { |mpf| LibGMP.mpf_set_q(mpf, mpq) }
end
Expand Down

0 comments on commit a9ee264

Please sign in to comment.