From 1fc4620e092d6d034dad71ae2f8dc4ff00536fe3 Mon Sep 17 00:00:00 2001 From: Sebastian Stock <42280794+sostock@users.noreply.github.com> Date: Sat, 18 Sep 2021 20:08:40 +0200 Subject: [PATCH 1/2] Add Base.hastypemax method --- src/HalfIntegers.jl | 1 + test/runtests.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/HalfIntegers.jl b/src/HalfIntegers.jl index 84616f6..0c1b427 100644 --- a/src/HalfIntegers.jl +++ b/src/HalfIntegers.jl @@ -646,6 +646,7 @@ function Base.tryparse(::Type{Half{T}}, s::AbstractString) where T<:Integer return isempty(matched.captures[2]) ? Half{T}(num) : half(num) end +Base.hastypemax(::Type{Half{T}}) where T<:Integer = Base.hastypemax(T) Base.typemax(::Type{Half{T}}) where T<:Integer = half(typemax(T)) Base.typemin(::Type{Half{T}}) where T<:Integer = half(typemin(T)) diff --git a/test/runtests.jl b/test/runtests.jl index 39585a7..470de2c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -413,7 +413,9 @@ end for T in (inttypes..., uinttypes...) @eval @test typemin(Half{$T}) === half(Half{$T}, typemin($T)) @eval @test typemax(Half{$T}) === half(Half{$T}, typemax($T)) + @eval @test Base.hastypemax(Half{$T}) end + @test !Base.hastypemax(BigHalfInt) end @testset "one/zero/isone/iszero" begin From a9b61a1b10c096cd4c7d83b59cb49ce048eaea51 Mon Sep 17 00:00:00 2001 From: Sebastian Stock <42280794+sostock@users.noreply.github.com> Date: Sat, 18 Sep 2021 20:20:00 +0200 Subject: [PATCH 2/2] Add changelog item --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e1efd4..3aafcbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +* ![Bugfix](https://img.shields.io/badge/-bugfix-purple) Added specialized `Base.hastypemax` method because the generic fallback doesn’t work correctly for `BigHalfInt`. ([#42](https://github.com/sostock/HalfIntegers.jl/pull/42)) + ## v1.4.1 * ![Maintenance](https://img.shields.io/badge/-maintenance-grey) Compatibility with SaferIntegers v3. ([#40](https://github.com/sostock/HalfIntegers.jl/pull/40))