Skip to content

Commit

Permalink
Added pow
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey M. Hoffstein committed Mar 6, 2012
1 parent 0a29305 commit 6d5f845
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions jl/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ function cmp(x::BigInt, y::BigInt)
ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_cmp), Int, (Ptr{Void}, Ptr{Void}),x.mpz, y.mpz)
end

macro define_pow ()
if WORD_SIZE == 64
:(function pow(x::BigInt, y::Uint64)
z = _jl_bigint_init()
ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_pow_ui), Void, (Ptr{Void}, Ptr{Void}, UInt64), z, x.mpz, y)
BigInt(z)
end)
else
:(function pow(x::BigInt, y::Uint32)
z = _jl_bigint_init()
ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_pow_ui), Void, (Ptr{Void}, Ptr{Void}, UInt32), z, x.mpz, y)
BigInt(z)
end)
end
end

@define_pow

==(x::BigInt, y::BigInt) = cmp(x,y) == 0
<=(x::BigInt, y::BigInt) = cmp(x,y) <= 0
>=(x::BigInt, y::BigInt) = cmp(x,y) >= 0
Expand Down

0 comments on commit 6d5f845

Please sign in to comment.