diff options
author | Kevin Ryde <user42@zip.com.au> | 2002-12-12 21:56:29 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2002-12-12 21:56:29 +0100 |
commit | b7418829cc6a34dd48c004c82fcd660d2bc5136e (patch) | |
tree | 1a8222cc40d19a616ad422e0268bbd6820cd5174 | |
parent | 3aa1afc5bb5838ead00df41de810cb420d1d6f94 (diff) | |
download | gmp-b7418829cc6a34dd48c004c82fcd660d2bc5136e.tar.gz |
* mpz/divis.c, mpz/divis_ui.c, mpz/cong.c, mpz/cong_ui.c: Allow d=0,
under the rule n==c mod d iff exists q satisfying n=c+q*d.
-rw-r--r-- | mpz/cong.c | 5 | ||||
-rw-r--r-- | mpz/cong_ui.c | 4 | ||||
-rw-r--r-- | mpz/divis.c | 17 | ||||
-rw-r--r-- | mpz/divis_ui.c | 6 |
4 files changed, 15 insertions, 17 deletions
diff --git a/mpz/cong.c b/mpz/cong.c index bfafb98c1..f01595adc 100644 --- a/mpz/cong.c +++ b/mpz/cong.c @@ -60,8 +60,9 @@ mpz_congruent_p (mpz_srcptr a, mpz_srcptr c, mpz_srcptr d) TMP_DECL (marker); dsize = SIZ(d); - if (dsize == 0) - DIVIDE_BY_ZERO; + if (UNLIKELY (dsize == 0)) + return (mpz_cmp (a, c) == 0); + dsize = ABS(dsize); dp = PTR(d); diff --git a/mpz/cong_ui.c b/mpz/cong_ui.c index ddf83faca..05927dc76 100644 --- a/mpz/cong_ui.c +++ b/mpz/cong_ui.c @@ -37,8 +37,8 @@ mpz_congruent_ui_p (mpz_srcptr a, unsigned long cu, unsigned long du) mp_size_t asize; mp_limb_t c, d, r; - if (du == 0) - DIVIDE_BY_ZERO; + if (UNLIKELY (du == 0)) + return (mpz_cmp_ui (a, cu) == 0); asize = SIZ(a); if (asize == 0) diff --git a/mpz/divis.c b/mpz/divis.c index ca65ea851..8c36c2c60 100644 --- a/mpz/divis.c +++ b/mpz/divis.c @@ -1,6 +1,5 @@ -/* mpz_divisible_p -- mpz by mpz divisibility test */ +/* mpz_divisible_p -- mpz by mpz divisibility test -/* Copyright 2001, 2002 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -18,8 +17,7 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ +MA 02111-1307, USA. */ #include "gmp.h" #include "gmp-impl.h" @@ -27,12 +25,11 @@ MA 02111-1307, USA. int mpz_divisible_p (mpz_srcptr a, mpz_srcptr d) { - mp_size_t dsize; + mp_size_t dsize = SIZ(d); + mp_size_t asize = SIZ(a); - dsize = SIZ(d); - if (dsize == 0) - DIVIDE_BY_ZERO; + if (UNLIKELY (dsize == 0)) + return (asize == 0); - return mpn_divisible_p (PTR(a), (mp_size_t) ABSIZ(a), - PTR(d), (mp_size_t) ABS(dsize)); + return mpn_divisible_p (PTR(a), ABS(asize), PTR(d), ABS(dsize)); } diff --git a/mpz/divis_ui.c b/mpz/divis_ui.c index 9d053ba87..1d5dc3cb2 100644 --- a/mpz/divis_ui.c +++ b/mpz/divis_ui.c @@ -31,10 +31,10 @@ mpz_divisible_ui_p (mpz_srcptr a, unsigned long d) mp_ptr ap; unsigned twos; - if (d == 0) - DIVIDE_BY_ZERO; - asize = SIZ(a); + if (UNLIKELY (d == 0)) + return (asize == 0); + if (asize == 0) /* 0 divisible by any d */ return 1; |