Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix using big rational #**with unsigned ints #10887

Merged
merged 5 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions spec/std/big/big_rational_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ describe BigRational do
result = br(17, 11) ** 5
result.should be_a(BigRational)
result.should eq(br(1419857, 161051))

result = br(17, 11) ** 5_u8
result.should be_a(BigRational)
result.should eq(br(1419857, 161051))
end

it "exponentiates with negative powers" do
Expand Down
5 changes: 5 additions & 0 deletions src/big/big_rational.cr
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ struct BigRational < Number
BigRational.new(numerator ** other, denominator ** other)
end

# :nodoc:
def **(other : UInt8 | UInt16 | UInt32 | UInt64 | UInt128) : BigRational
stakach marked this conversation as resolved.
Show resolved Hide resolved
BigRational.new(numerator ** other, denominator ** other)
end

# Returns a new `BigRational` as 1/r.
#
# This will raise an exception if rational is 0.
Expand Down