JuliaMath / DoubleDouble.jl

Extended precision arithmetic for Julia (deprecated)
Other
26 stars 16 forks source link

Constructor of Double for non-Floats #17

Closed GregPlowman closed 7 years ago

GregPlowman commented 8 years ago

One can easily create a Double from a Real using Double(x), but you can't use Double{Float64}(x).

I understand Double is not yet a drop-in replacement datatype, but the latter could be useful when changing datatypes throughout some section of code.

I don't fully understand what would be required, but could one of the following work?

Double{T<:AbstractFloat}(x::Real) = convert(Double{T}, T(x))

Or maybe its better to widen x argument to include all Reals rather than just AbstractFloats:

function convert{T<:AbstractFloat}(::Type{Double{T}}, x::Real) 
    z = convert(T, x) 
    Double(z, convert(T, x-z)) 
end

Or maybe this doesn't make sense at all.

GregPlowman commented 7 years ago

Fixed by #18