Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ end

limbs_write!(x::BigInt, a) = ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a)
limbs_finish!(x::BigInt, a) = ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a)
import!(x::BigInt, a, b, c, d, e, f) = ccall((:__gmpz_import, libgmp), Cvoid,
(mpz_t, Csize_t, Cint, Csize_t, Cint, Csize_t, Ptr{Cvoid}), x, a, b, c, d, e, f)

setbit!(x, a) = (ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a); x)
tstbit(a::BigInt, b) = ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool
Expand Down
38 changes: 38 additions & 0 deletions test/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,44 @@ end
@test string(big(0), base = rand(2:62), pad = 0) == ""
end

@testset "Base.GMP.MPZ.export!" begin

function Base_GMP_MPZ_import!(x::BigInt, n::AbstractVector{T}; order::Integer=-1, nails::Integer=0, endian::Integer=0) where {T<:Base.BitInteger}
ccall((:__gmpz_import, Base.GMP.MPZ.libgmp),
Cvoid,
(Base.GMP.MPZ.mpz_t, Csize_t, Cint, Csize_t, Cint, Csize_t, Ptr{Cvoid}),
x, length(n), order, sizeof(T), endian, nails, n)
return x
end
# test import
bytes_to_import_from = Vector{UInt8}([1, 0])
int_to_import_to = BigInt()
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_import_from, order=0)
@test int_to_import_to == BigInt(256)

# test export
int_to_export_from = BigInt(256)
bytes_to_export_to = Vector{UInt8}(undef, 2)
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
@test all(bytes_to_export_to .== bytes_to_import_from)

# test both composed import(export) is identity
int_to_export_from = BigInt(256)
bytes_to_export_to = Vector{UInt8}(undef, 2)
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
int_to_import_to = BigInt()
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_export_to, order=0)
@test int_to_export_from == int_to_import_to

# test both composed export(import) is identity
bytes_to_import_from = Vector{UInt8}([1, 0])
int_to_import_to = BigInt()
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_import_from, order=0)
bytes_to_export_to = Vector{UInt8}(undef, 2)
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
@test all(bytes_to_export_to .== bytes_to_import_from)
end

@test isqrt(big(4)) == 2
@test isqrt(big(5)) == 2

Expand Down
Loading