Skip to content

Commit

Permalink
Merge #224
Browse files Browse the repository at this point in the history
224: Support more chip math r=charleskawczynski a=charleskawczynski



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
  • Loading branch information
bors[bot] and charleskawczynski committed Aug 27, 2023
2 parents d41353e + 36572e6 commit ce6b868
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

0 comments on commit ce6b868

Please sign in to comment.