Skip to content

Commit 47c58ab

Browse files
Merge pull request #197 from araujoms/infnan
Fix conversion from Inf
2 parents 8b58185 + f685a21 commit 47c58ab

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Double.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Convert `x` to an extended precision `Double64`.
105105
lo = Float64(x - Float64(hi))
106106
else
107107
hi = Float64(x)
108-
lo = NaN
108+
lo = hi
109109
end
110110
return Double64(hi, lo)
111111
end
@@ -120,7 +120,7 @@ Convert `x` to an extended precision `Double32`.
120120
lo = Float32(x - Float32(hi))
121121
else
122122
hi = Float32(x)
123-
lo = NaN32
123+
lo = hi
124124
end
125125
return Double32(hi, lo)
126126
end
@@ -136,7 +136,7 @@ Convert `x` to an extended precision `Double16`.
136136
lo = Float16(x - Float16(hi))
137137
else
138138
hi = Float16(x)
139-
lo = NaN16
139+
lo = hi
140140
end
141141
return Double16(hi, lo)
142142
end

test/specialvalues.jl

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,25 @@ end
2929
@testset "Inf and NaN layout $T" for T in (Double16, Double32, Double64)
3030
@test isinf(HI(T(Inf)))
3131
@test isnan(HI(T(NaN)))
32-
@test isnan(LO(T(Inf)))
32+
@test isinf(LO(T(Inf)))
3333
@test isnan(LO(T(NaN)))
3434
end
3535

36+
@testset "Inf and NaN conversion" for T in (Double16, Double32, Double64)
37+
for S in (BigFloat, Float128)
38+
@test isnan(S(T(NaN)))
39+
@test isinf(S(T(Inf)))
40+
@test S(T(Inf)) > 0
41+
@test isinf(S(T(-Inf)))
42+
@test S(T(-Inf)) < 0
43+
@test isnan(T(S(NaN)))
44+
@test isinf(T(S(Inf)))
45+
@test T(S(Inf)) > 0
46+
@test isinf(T(S(-Inf)))
47+
@test T(S(-Inf)) < 0
48+
end
49+
end
50+
3651
@testset "NaNs $T" for T in (Double16, Double32, Double64)
3752
@test isnan(exp(T(NaN)))
3853
@test isnan(log(T(NaN)))

0 commit comments

Comments
 (0)