Skip to content

Commit

Permalink
Fix bigfloat conversion for Julia v1.12 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalphAS authored Oct 18, 2024
1 parent a90d304 commit 514d07f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Quadmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ Float128(x::Irrational{T}) where {T} = Float128(BigFloat(x))

import Base.MPFR

@static if VERSION >= v"1.12.0-DEV.1343"
const _big_setindex! = Base.setindex!
const _big_getindex = Base.getindex
else
const _big_setindex! = unsafe_store!
const _big_getindex = unsafe_load
end

function BigFloat(x::Float128; precision=precision(BigFloat))
if !isfinite(x) || iszero(x)
@static if VERSION < v"1.1"
Expand All @@ -490,13 +498,13 @@ function BigFloat(x::Float128; precision=precision(BigFloat))
i = cld(precision, sizeof(MPFR.Limb)*8)
while u != 0
w = (u >> (128-sizeof(MPFR.Limb)*8)) % MPFR.Limb
unsafe_store!(b.d, w, i)
_big_setindex!(b.d, w, i)
i -= 1
u <<= sizeof(MPFR.Limb)*8
end
# set remaining bits to zero
while i > 0
unsafe_store!(b.d, zero(MPFR.Limb), i)
_big_setindex!(b.d, zero(MPFR.Limb), i)
i -= 1
end

Expand Down Expand Up @@ -547,7 +555,7 @@ function Float128(x::BigFloat)
j = 113
while i > 0
j -= sizeof(MPFR.Limb)*8
u |= (unsafe_load(y.d, i) % UInt128) << j
u |= (_big_getindex(y.d, i) % UInt128) << j
i -= 1
end
u &= significand_mask(Float128)
Expand Down

0 comments on commit 514d07f

Please sign in to comment.