Skip to content

Commit 514d07f

Browse files
authored
Fix bigfloat conversion for Julia v1.12 (#75)
1 parent a90d304 commit 514d07f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Quadmath.jl

+11-3
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ Float128(x::Irrational{T}) where {T} = Float128(BigFloat(x))
466466

467467
import Base.MPFR
468468

469+
@static if VERSION >= v"1.12.0-DEV.1343"
470+
const _big_setindex! = Base.setindex!
471+
const _big_getindex = Base.getindex
472+
else
473+
const _big_setindex! = unsafe_store!
474+
const _big_getindex = unsafe_load
475+
end
476+
469477
function BigFloat(x::Float128; precision=precision(BigFloat))
470478
if !isfinite(x) || iszero(x)
471479
@static if VERSION < v"1.1"
@@ -490,13 +498,13 @@ function BigFloat(x::Float128; precision=precision(BigFloat))
490498
i = cld(precision, sizeof(MPFR.Limb)*8)
491499
while u != 0
492500
w = (u >> (128-sizeof(MPFR.Limb)*8)) % MPFR.Limb
493-
unsafe_store!(b.d, w, i)
501+
_big_setindex!(b.d, w, i)
494502
i -= 1
495503
u <<= sizeof(MPFR.Limb)*8
496504
end
497505
# set remaining bits to zero
498506
while i > 0
499-
unsafe_store!(b.d, zero(MPFR.Limb), i)
507+
_big_setindex!(b.d, zero(MPFR.Limb), i)
500508
i -= 1
501509
end
502510

@@ -547,7 +555,7 @@ function Float128(x::BigFloat)
547555
j = 113
548556
while i > 0
549557
j -= sizeof(MPFR.Limb)*8
550-
u |= (unsafe_load(y.d, i) % UInt128) << j
558+
u |= (_big_getindex(y.d, i) % UInt128) << j
551559
i -= 1
552560
end
553561
u &= significand_mask(Float128)

0 commit comments

Comments
 (0)