Skip to content

Commit a0766bd

Browse files
authoredOct 11, 2022
don't specialize convert (#25)
* don't specialize convert * version bump to v0.1.6 * tests for RealInfinity conversion
1 parent 9410e0e commit a0766bd

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed
 

‎Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Infinities"
22
uuid = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
33
authors = ["Sheehan Olver <solver@mac.com>"]
4-
version = "0.1.5"
4+
version = "0.1.6"
55

66
[compat]
77
julia = "1"

‎src/Infinities.jl

+12-18
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ const ∞ = Infinity()
2828
show(io::IO, ::Infinity) = print(io, "")
2929
string(::Infinity) = ""
3030

31-
convert(::Type{Float64}, ::Infinity) = Inf64
32-
convert(::Type{Float32}, ::Infinity) = Inf32
33-
convert(::Type{Float16}, ::Infinity) = Inf16
34-
Base.Float64(::Infinity) = convert(Float64, ∞)
35-
Base.Float32(::Infinity) = convert(Float32, ∞)
36-
Base.Float16(::Infinity) = convert(Float16, ∞)
37-
Base.BigFloat(::Infinity) = BigFloat(Inf)
38-
convert(::Type{AF}, ::Infinity) where AF<:AbstractFloat = convert(AF, Inf)
31+
_convert(::Type{Float64}, ::Infinity) = Inf64
32+
_convert(::Type{Float32}, ::Infinity) = Inf32
33+
_convert(::Type{Float16}, ::Infinity) = Inf16
34+
_convert(::Type{T}, ::Infinity) where {T<:Real} = convert(T, Inf)::T
35+
(::Type{T})(x::Infinity) where {T<:Real} = _convert(T, x)
3936

4037

4138
sign(y::Infinity) = 1
@@ -131,16 +128,13 @@ isinf(::RealInfinity) = true
131128
isfinite(::RealInfinity) = false
132129

133130
promote_rule(::Type{Infinity}, ::Type{RealInfinity}) = RealInfinity
134-
convert(::Type{RealInfinity}, ::Infinity) = RealInfinity(false)
135-
136-
convert(::Type{Float64}, x::RealInfinity) = sign(x)*Inf64
137-
convert(::Type{Float32}, x::RealInfinity) = sign(x)*Inf32
138-
convert(::Type{Float16}, x::RealInfinity) = sign(x)*Inf16
139-
Base.Float64(x::RealInfinity) = convert(Float64, x)
140-
Base.Float32(x::RealInfinity) = convert(Float32, x)
141-
Base.Float16(x::RealInfinity) = convert(Float16, x)
142-
Base.BigFloat(x::RealInfinity) = sign(x)*BigFloat(Inf)
143-
convert(::Type{AF}, x::RealInfinity) where AF<:AbstractFloat = sign(x)*convert(AF, Inf)
131+
_convert(::Type{RealInfinity}, ::Infinity) = RealInfinity(false)
132+
133+
_convert(::Type{Float16}, x::RealInfinity) = sign(x)*Inf16
134+
_convert(::Type{Float32}, x::RealInfinity) = sign(x)*Inf32
135+
_convert(::Type{Float64}, x::RealInfinity) = sign(x)*Inf64
136+
_convert(::Type{T}, x::RealInfinity) where {T<:Real} = sign(x)*convert(T, Inf)
137+
(::Type{T})(x::RealInfinity) where {T<:Real} = _convert(T, x)
144138

145139

146140
signbit(y::RealInfinity) = y.signbit

‎test/runtests.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ import Infinities: Infinity
8787
@test convert(Float32, ∞) Float32(∞) Inf32
8888
@test convert(Float16, ∞) Float16(∞) Inf16
8989
@test convert(BigFloat, ∞)::BigFloat == BigFloat(∞)::BigFloat == BigFloat(Inf)
90+
@test convert(RealInfinity, ∞) isa RealInfinity
91+
@test convert(RealInfinity, ∞) == Inf
9092
end
9193
end
9294

@@ -287,4 +289,4 @@ import Infinities: Infinity
287289
end
288290

289291

290-
include("test_cardinality.jl")
292+
include("test_cardinality.jl")

4 commit comments

Comments
 (4)

jishnub commented on Oct 11, 2022

@jishnub
MemberAuthor

Coverage report seems inaccurate, as codecov isn't being able to fetch results. Maybe this can be tagged, as I don't think coverage should be affected. @dlfivefifty

jishnub commented on Oct 13, 2022

@jishnub
MemberAuthor

Gentle bump @dlfivefifty

dlfivefifty commented on Oct 13, 2022

@dlfivefifty
Member

JuliaRegistrator commented on Oct 13, 2022

@JuliaRegistrator

Registration pull request created: JuliaRegistries/General/70105

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.6 -m "<description of version>" a0766bd3fd3207c177b4c80caf202826a0ece8a2
git push origin v0.1.6
Please sign in to comment.