Skip to content
This repository was archived by the owner on Dec 10, 2023. It is now read-only.
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
3 changes: 3 additions & 0 deletions src/DoubleDouble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ convert{T<:AbstractFloat}(::Type{Double{T}}, x::Irrational) = convert(Double{T},
convert(::Type{BigFloat}, x::Single) = big(x.hi)
convert(::Type{BigFloat}, x::Double) = big(x.hi) + big(x.lo)

convert{T}(::Type{Single{T}}, x::Integer) = convert(Single{T}, T(x))
convert{T}(::Type{Double{T}}, x::Integer) = convert(Double{T}, T(x))

promote_rule{T<:AbstractFloat}(::Type{Single{T}}, ::Type{T}) = Single{T}
promote_rule{T<:AbstractFloat}(::Type{Double{T}}, ::Type{T}) = Double{T}
Expand All @@ -93,6 +95,7 @@ promote_rule{T<:AbstractFloat}(::Type{Double{T}}, ::Type{Single{T}}) = Double{T}
promote_rule{s,T<:AbstractFloat}(::Type{Irrational{s}}, ::Type{Single{T}}) = Double{Float64}


Single(x::Real) = convert(Single{Float64}, Float64(x))

Double(x::Real) = convert(Double{Float64}, Float64(x))
Double(x::BigFloat) = convert(Double{Float64}, x)
Expand Down
15 changes: 13 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@ a = Double(big"3.1")
@test a == Double(3.1, -8.881784197001253e-17)
@test BigFloat(a) == big"3.099999999999999999999999999999995069619342368676216176696466982586064542459781"

@test Double(3) == Double(3.0, 0.0)
@test Double(big(3)) == Double(3.0, 0.0)
@test Single(3) === Single(3.0)
@test Double(3) === Double(3.0, 0.0)
@test Double(big(3)) === Double(3.0, 0.0)

@test convert(Single{Float64}, 1) === Single(1.0)
@test convert(Single{Float32}, 1) === Single(1.0f0)
@test convert(Double{Float64}, 1) === Double(1.0, 0.0)
@test convert(Double{Float32}, 1) === Double(1.0f0, 0.0f0)

@test Single{Float32}(3) === Single{Float32}(3.0f0)
@test Double{Float32}(3) === Double{Float32}(3.0f0, 0.0f0)
@test Single{Float32}(BigFloat(3)) === Single{Float32}(3.0f0)
@test Double{Float32}(BigFloat(3)) === Double{Float32}(3.0f0, 0.0f0)