Skip to content

Commit 43a14f8

Browse files
authored
Base.MPFR: implement signbit in Julia without a ccall (#50675)
This accesses MPFR's internals, but it should be stable.
1 parent 4cdd8cd commit 43a14f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

base/mpfr.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,10 @@ cmp(x::CdoubleMax, y::BigFloat) = -cmp(y,x)
885885
<=(x::BigFloat, y::CdoubleMax) = !isnan(x) && !isnan(y) && cmp(x,y) <= 0
886886
<=(x::CdoubleMax, y::BigFloat) = !isnan(x) && !isnan(y) && cmp(y,x) >= 0
887887

888-
signbit(x::BigFloat) = ccall((:mpfr_signbit, libmpfr), Int32, (Ref{BigFloat},), x) != 0
888+
# Note: this inlines the implementation of `mpfr_signbit` to avoid a
889+
# `ccall`.
890+
signbit(x::BigFloat) = signbit(x.sign)
891+
889892
function sign(x::BigFloat)
890893
c = cmp(x, 0)
891894
(c == 0 || isnan(x)) && return x

0 commit comments

Comments
 (0)