Skip to content

Commit 0f30b79

Browse files
Update convert.jl
1 parent beb563c commit 0f30b79

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/type/convert.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ convert(::Type{Float32}, x::Double32) = HI(x)
1111
convert(::Type{Float16}, x::Double16) = HI(x)
1212

1313
convert(::Type{DoubleFloat{T}}, x::I) where {T<:IEEEFloat, I<:Integer} = DoubleFloat{T}(T(x))
14-
convert(::Type{I}, x::DoubleFloat{T}) where {T<:IEEEFloat, I<:Integer} = I(round(BigInt, BigFloat(HI(x))+ BigFloat(LO(x))))
14+
function convert(::Type{I}, x::DoubleFloat{T}) where {T<:IEEEFloat, I<:Integer}
15+
bi = trunc(BigInt, BigFloat(HI(x)) + BigFloat(LO(x)))
16+
abi = abs(bi)
17+
if abi <= typemax(Int)
18+
convert(Int, bi)
19+
elseif abi <= typemax(Int64)
20+
convert(Int64, bi)
21+
elseif abi <= typemax(Int128)
22+
convert(Int128, bi)
23+
else
24+
bi
25+
end
26+
end
1527

1628
function convert(::Type{BigFloat}, x::DoubleFloat{T}) where {T<:IEEEFloat}
1729
res = Base.BigFloat(HI(x)) + Base.BigFloat(LO(x))

0 commit comments

Comments
 (0)