I need to call a MPFR library function whose signature is int mpfr_sub_ui(mpfr_t rop, mpfr_t op1, unsigned long int op2, mpfr_rnd_t rnd).
The manual says that unsigned long is an Int on Unix and an Int32 on Windows. Is there a way to ccall the library function that works on both Unix and Windows?
Culong should do the right thing:
julia> Culong
UInt64
1 Like
The library has also function mpfr_sub_si with signature long int. What I should have asked is how should the Julia wrappers be defined.
function mpfr_sub(rop::BigFloat, op1::BigFloat, op2::UInt, rnd) # for unsigned long int
ccall((:mpfr_sub_ui, :libmpfr), Int32,
(Ref{BigFloat}, Ref{BigFloat}, Culong, MPFR.MPFRRoundingMode),
rop, op1, op2, rnd)
end
and
function mpfr_sub(rop::BigFloat, op1::BigFloat, op2::Int, rnd) # for long int
ccall((:mpfr_sub_si, :libmpfr), Int32,
(Ref{BigFloat}, Ref{BigFloat}, Clong, MPFR.MPFRRoundingMode),
rop, op1, op2, rnd)
end
Julia’s MPFR module in Base uses ClongMax and CulongMax defined in GMP:
julia> Base.GMP.CulongMax
Union{UInt16, UInt32, UInt8}
julia> Base.GMP.ClongMax
Union{Int16, Int32, Int8}
Because you are on a Unix-like system? On Windows, I get:
julia> Culong
UInt32