Skip to content
This repository was archived by the owner on Dec 10, 2023. It is now read-only.

Constructor of Double for non-Floats #17

Closed
GregPlowman opened this issue Jul 31, 2016 · 1 comment
Closed

Constructor of Double for non-Floats #17

GregPlowman opened this issue Jul 31, 2016 · 1 comment

Comments

@GregPlowman
Copy link
Contributor

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
Copy link
Contributor Author

Fixed by #18

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant