Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion from Inf #197

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading