From 3b5c804ae3221ab8e81a8d0958918c77c11307e2 Mon Sep 17 00:00:00 2001 From: Sebastian Stock <42280794+sostock@users.noreply.github.com> Date: Fri, 11 Jun 2021 20:44:11 +0200 Subject: [PATCH] Simplify half(Half{T}, x) implementation --- src/HalfIntegers.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/HalfIntegers.jl b/src/HalfIntegers.jl index 6c5c2cd..e33306b 100644 --- a/src/HalfIntegers.jl +++ b/src/HalfIntegers.jl @@ -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)