Skip to content

Commit

Permalink
Simplify half(Half{T}, x) implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock committed Jun 11, 2021
1 parent 2cfdaeb commit 3b5c804
Showing 1 changed file with 2 additions and 4 deletions.
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

0 comments on commit 3b5c804

Please sign in to comment.