Skip to content

Commit

Permalink
Merge pull request #224 from charleskawczynski/ck/chip_math
Browse files Browse the repository at this point in the history
Support more chip math
  • Loading branch information
charleskawczynski authored Aug 27, 2023
2 parents d41353e + 36572e6 commit bc0b10d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TexasHoldem"
uuid = "6cef90fc-eb55-4a2a-97d0-7ecce2b738fe"
authors = ["Charles Kawczynski <kawczynski.charles@gmail.com>"]
version = "0.4.0"
version = "0.4.1"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
10 changes: 10 additions & 0 deletions src/chips.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ end

Base.:(+)(x::Int, y::SimpleRatio) = SimpleRatio(x*y.den + y.num, y.den)
Base.:(-)(x::Int, y::SimpleRatio) = SimpleRatio(x*y.den - y.num, y.den)
Base.:(+)(x::SimpleRatio, y::Int) = SimpleRatio(y*x.den + x.num, x.den)
Base.:(-)(x::SimpleRatio, y::Int) = SimpleRatio(y*x.den - x.num, x.den)
Base.:(+)(x::SimpleRatio) = x
Base.:(-)(x::SimpleRatio) = SimpleRatio(-x.num, x.den)
Base.:(+)(x::SimpleRatio, y::SimpleRatio) =
x.den == y.den ? SimpleRatio(x.num + y.num, x.den) :
SimpleRatio(x.num*y.den + x.den*y.num, x.den*y.den)

Base.abs(x::SimpleRatio) = SimpleRatio(Base.abs(x.num), Base.abs(x.den))
Base.:(-)(x::SimpleRatio, y::SimpleRatio) =
x.den == y.den ? SimpleRatio(x.num - y.num, x.den) :
SimpleRatio(x.num*y.den - x.den*y.num, x.den*y.den)
Expand Down Expand Up @@ -85,6 +90,11 @@ Base.:(+)(a::Chips, b::Chips) = Chips(a.n+b.n, a.frac+b.frac)
Base.:(-)(a::Chips, b::Chips) = Chips(a.n-b.n, a.frac-b.frac)
Base.:(+)(a::Chips, b::Int) = Chips(a.n+b, a.frac)
Base.:(-)(a::Chips, b::Int) = Chips(a.n-b, a.frac)
Base.:(+)(a::Int, b::Chips) = Chips(a+b.n, b.frac)
Base.:(-)(a::Int, b::Chips) = Chips(a-b.n, -b.frac)
Base.:(+)(a::Chips) = a
Base.:(-)(a::Chips) = Chips(-a.n, -a.frac)
Base.abs(a::Chips) = Chips(abs(a.n), abs(a.frac))

Base.:(==)(x::Chips, y::Chips) = x.n == y.n && x.frac == y.frac
Base.:(==)(x::Chips, y::Int) = x.n == y && x.frac == 0
Expand Down

2 comments on commit bc0b10d

@charleskawczynski
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90359

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" bc0b10de8d28051f26757749a377c55f18e67aa6
git push origin v0.4.1

Please sign in to comment.