dzhang314 / MultiFloats.jl

Fast, SIMD-accelerated extended-precision arithmetic for Julia
MIT License
75 stars 10 forks source link

Promotion of Irrationals #21

Closed jishnub closed 1 week ago

jishnub commented 3 years ago
julia> pi * Float64x4(2)
ERROR: MethodError: Cannot `convert` an object of type Irrational{:π} to an object of type NTuple{4, Float64}

Perhaps there might be a way to convert these to BigFloat and then to MultiFloats

julia> 2Float64x4(big(pi))
6.283185307179586476925286766559005768394338798750211641949889184604
dzhang314 commented 3 years ago

Hey @jishnub , good catch! I totally overlooked this in my own testing. You're right, a conversion to BigFloat (with the precision set to the appropriate level) and then to MultiFloat is absolutely the right way to do it. I'll get this implemented in the next version of MultiFloats.jl.

goulart-paul commented 11 months ago

I hit the same problem. A fix could be something like:

function MultiFloat{T,N}(x::Union{Rational{S},Irrational{S}}) where {S,T,N}
    MultiFloat{T,N}(BigFloat(x; precision = precision(MultiFloat{T,N})))
end

then I get

Float64x2(π)
3.141592653589793238462643383279506
dzhang314 commented 1 week ago

Hey everyone! It's been ages since I last looked at MultiFloats.jl, but I've finally pushed a fix for this in commit 02091e0.