Skip to content

Commit a43f400

Browse files
Merge pull request #20 from anriseth/fixnaninf
Catch Inf and NaN generation
2 parents cfa1a18 + 8b38c24 commit a43f400

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Double.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ const QuadrupleF16 = DoubleFloat{DoubleFloat{Float16}}
6666
@inline DoubleFloat(x::Tuple{T,T}) where {T<:AbstractFloat} = DoubleFloat{T}(x[1], x[2])
6767

6868
@inline function Double64(x::T) where {T<:IEEEFloat}
69-
!isfinite(x) && return(Double64(Float64(x),zero(T)))
69+
!isfinite(x) && return(DoubleFloat(Float64(x),Float64(NaN)))
7070
hi = Float64(x)
7171
lo = Float64(x - Float64(hi))
7272
return Double64(hi, lo)
7373
end
7474
@inline function Double32(x::T) where {T<:IEEEFloat}
75-
!isfinite(x) && return(Double32(Float32(x),zero(T)))
75+
!isfinite(x) && return(DoubleFloat(Float32(x),Float32(NaN)))
7676
hi = Float32(x)
7777
lo = Float32(x - Float64(hi))
7878
return Double32(hi, lo)
7979
end
8080
@inline function Double16(x::T) where {T<:IEEEFloat}
81-
!isfinite(x) && return(Double16(Float16(x),zero(T)))
81+
!isfinite(x) && return(DoubleFloat(Float16(x),Float16(NaN)))
8282
hi = Float16(x)
8383
lo = Float16(x - Float64(hi))
8484
return Double16(hi, lo)

src/DoubleFloats.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using Random
5151

5252
using AccurateArithmetic
5353

54-
include("Double.jl") # Double64, Double16, Double16
54+
include("Double.jl") # Double64, Double32, Double16
5555

5656
include("doubletriple/double.jl")
5757
include("doubletriple/double_consts.jl")

test/specialvalues.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,21 @@ end
99
# Double16 is a special case
1010
@test isinteger(maxintfloat(Double16))
1111
@test maxintfloat(Double16) == floatmax(Double16)
12+
13+
14+
@testset "Inf and NaN generation $T" for T in (Double16, Double32, Double64)
15+
@test T(Inf) == inf(T)
16+
@test T(Inf) == posinf(T)
17+
@test T(-Inf) == neginf(T)
18+
@test T(NaN) == nan(T)
19+
20+
@test T(Inf32) == inf(T)
21+
@test T(Inf32) == posinf(T)
22+
@test T(-Inf32) == neginf(T)
23+
@test T(NaN32) == nan(T)
24+
25+
@test T(Inf16) == inf(T)
26+
@test T(Inf16) == posinf(T)
27+
@test T(-Inf16) == neginf(T)
28+
@test T(NaN16) == nan(T)
29+
end

0 commit comments

Comments
 (0)