Skip to content

Commit a642004

Browse files
committed
remove default constructor, fix ambiguities
1 parent 8469c23 commit a642004

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Quadmath.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ const Cfloat128 = NTuple{2,VecElement{Float64}}
8383

8484
struct Float128 <: AbstractFloat
8585
data::Cfloat128
86+
function Float128(data::Cfloat128)
87+
new(data)
88+
end
8689
end
8790
convert(::Type{Float128}, x::Number) = Float128(x)
8891

@@ -145,6 +148,10 @@ Float128(x::Float128) = x
145148
Float128(x::Float16) = Float128(Float32(x))
146149
Float16(x::Float128) = Float16(Float64(x)) # TODO: avoid double rounding
147150

151+
# TwicePrecision
152+
Float128(x::Base.TwicePrecision{Float64}) =
153+
Float128(x.hi) + Float128(x.lo)
154+
148155
# integer -> Float128
149156
@assume_effects :foldable Float128(x::Int32) =
150157
Float128(@ccall(quadoplib.__floatsitf(x::Int32)::Cfloat128))
@@ -181,7 +188,7 @@ function Float128(x::UInt128)
181188
else
182189
y1 = reinterpret(Float64,UInt64(d >> 64))
183190
y2 = reinterpret(Float64,(d % UInt64))
184-
return Float128((y2,y1))
191+
return Float128((VecElement(y2),VecElement(y1)))
185192
end
186193
end
187194

@@ -205,7 +212,7 @@ function Float128(x::Int128)
205212
else
206213
y1 = reinterpret(Float64,UInt64(d >> 64))
207214
y2 = reinterpret(Float64,(d % UInt64))
208-
Float128((y2,y1))
215+
Float128((VecElement(y2),VecElement(y1)))
209216
end
210217
end
211218

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ end
226226
@test !(1//3 > fnan)
227227
end
228228

229+
@testset "ambiguities" begin
230+
@test Float128(1.0+0.0im) === Float128(1.0)
231+
@test_throws InexactError Float128(1.0+2.0im)
232+
233+
@test Float128('a') === Float128(Int('a'))
234+
235+
t_hi = 0.1
236+
t_lo = Float64(big"0.1" - t_hi)
237+
@test Float128(Base.TwicePrecision(t_hi, t_lo)) == Float128(t_hi) + Float128(t_lo)
238+
end
239+
229240
include("hashing.jl")
230241

231242
include("specfun.jl")

0 commit comments

Comments
 (0)