Skip to content

Commit

Permalink
Added SB-GMP:MPZ-DIVISIBLE-P.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmarek committed Mar 3, 2020
1 parent 07fcf44 commit 2d2d6fb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contrib/sb-gmp/gmp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#:mpz-powm
#:mpz-pow
#:mpz-gcd
#:mpz-divisible-p
#:mpz-lcm
#:mpz-sqrt
#:mpz-probably-prime-p
Expand Down Expand Up @@ -246,6 +247,7 @@ pre-allocated bignum. The allocated bignum-length must be (1+ COUNT)."
(declaim (inline __gmpz_mul_2exp
__gmpz_fdiv_q_2exp
__gmpz_pow_ui
__gmpz_divisible_p
__gmpz_probab_prime_p
__gmpz_fac_ui
__gmpz_2fac_ui
Expand All @@ -270,6 +272,10 @@ pre-allocated bignum. The allocated bignum-length must be (1+ COUNT)."
(b (* (struct gmpint)))
(e unsigned-long))

(define-alien-routine __gmpz_divisible_p int
(n (* (struct gmpint)))
(d (* (struct gmpint))))

(define-alien-routine __gmpz_probab_prime_p int
(n (* (struct gmpint)))
(reps int))
Expand Down Expand Up @@ -461,6 +467,16 @@ pre-allocated bignum. The allocated bignum-length must be (1+ COUNT)."
(/= 0 (slot result 'mp_size)))
(__gmpz_add (addr result) (addr result) (addr gb))))))

(defun mpz-divisible-p (n d)
"Returns T if (ZEROP (MOD N D))."
(declare (optimize (speed 3) (space 3) (safety 0))
(type integer n d))
(with-mpz-vars ((n gn) (d gd))
(not
(zerop
(__gmpz_divisible_p (addr gn) (addr gd))))))


(defgmpfun mpz-cdiv (n d)
(let ((size (1+ (max (blength n)
(blength d)))))
Expand Down

0 comments on commit 2d2d6fb

Please sign in to comment.