Skip to content

Commit

Permalink
Merge pull request #197 from araujoms/infnan
Browse files Browse the repository at this point in the history
Fix conversion from Inf
  • Loading branch information
JeffreySarnoff authored Apr 12, 2024
2 parents 8b58185 + f685a21 commit 47c58ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Double.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Convert `x` to an extended precision `Double64`.
lo = Float64(x - Float64(hi))
else
hi = Float64(x)
lo = NaN
lo = hi
end
return Double64(hi, lo)
end
Expand All @@ -120,7 +120,7 @@ Convert `x` to an extended precision `Double32`.
lo = Float32(x - Float32(hi))
else
hi = Float32(x)
lo = NaN32
lo = hi
end
return Double32(hi, lo)
end
Expand All @@ -136,7 +136,7 @@ Convert `x` to an extended precision `Double16`.
lo = Float16(x - Float16(hi))
else
hi = Float16(x)
lo = NaN16
lo = hi
end
return Double16(hi, lo)
end
Expand Down
17 changes: 16 additions & 1 deletion test/specialvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ end
@testset "Inf and NaN layout $T" for T in (Double16, Double32, Double64)
@test isinf(HI(T(Inf)))
@test isnan(HI(T(NaN)))
@test isnan(LO(T(Inf)))
@test isinf(LO(T(Inf)))
@test isnan(LO(T(NaN)))
end

@testset "Inf and NaN conversion" for T in (Double16, Double32, Double64)
for S in (BigFloat, Float128)
@test isnan(S(T(NaN)))
@test isinf(S(T(Inf)))
@test S(T(Inf)) > 0
@test isinf(S(T(-Inf)))
@test S(T(-Inf)) < 0
@test isnan(T(S(NaN)))
@test isinf(T(S(Inf)))
@test T(S(Inf)) > 0
@test isinf(T(S(-Inf)))
@test T(S(-Inf)) < 0
end
end

@testset "NaNs $T" for T in (Double16, Double32, Double64)
@test isnan(exp(T(NaN)))
@test isnan(log(T(NaN)))
Expand Down

0 comments on commit 47c58ab

Please sign in to comment.