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

Simplify half(Half{T}, x) implementation #34

Merged
merged 1 commit into from
Jun 11, 2021
Merged
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
6 changes: 2 additions & 4 deletions src/HalfIntegers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,12 @@ that, e.g., `HalfInt` can be used instead of `Half{Int}`:
"""
struct Half{T<:Integer} <: HalfInteger
twice::T
# Inner constructor that is only used to define half(::Type{Half{T}}, x)
Half{T}(::Val{:inner}, twice) where T<:Integer = new(twice)

global half(::Type{Half{T}}, x::Number) where T<:Integer = new{T}(x)
end
Half{T}(x::Real) where T<:Integer = half(Half{T}, twice(T,x))
Half{T}(x::Half{T}) where T<:Integer = x

half(::Type{Half{T}}, x::Number) where T<:Integer = Half{T}(Val{:inner}(), x)

twice(x::Half) = x.twice

Base.promote_rule(::Type{Half{H}}, T::Type{<:Real}) where H<:Integer = promote_type(Rational{H}, T)
Expand Down