From 1a05a8ef4cf287194d595bc6749f6ed6585d3352 Mon Sep 17 00:00:00 2001 From: mdw Date: Sun, 8 Oct 2000 12:06:12 +0000 Subject: [PATCH] Provide @mpx_ueq@ for rapidly testing equality of two integers. --- mpx.c | 47 ++++++++++++++++++++++++++++++++++++----------- mpx.h | 18 +++++++++++++++++- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/mpx.c b/mpx.c index 327699c..13b6fa0 100644 --- a/mpx.c +++ b/mpx.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mpx.c,v 1.9 2000/06/26 07:52:50 mdw Exp $ + * $Id: mpx.c,v 1.10 2000/10/08 12:06:12 mdw Exp $ * * Low-level multiprecision arithmetic * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: mpx.c,v $ + * Revision 1.10 2000/10/08 12:06:12 mdw + * Provide @mpx_ueq@ for rapidly testing equality of two integers. + * * Revision 1.9 2000/06/26 07:52:50 mdw * Portability fix for the bug fix. * @@ -423,6 +426,29 @@ void mpx_2c(mpw *dv, mpw *dvl, const mpw *v, const mpw *vl) MPX_UADDN(dv, dvl, 1); } +/* --- @mpx_ueq@ --- * + * + * Arguments: @const mpw *av, *avl@ = first argument vector base and limit + * @const mpw *bv, *bvl@ = second argument vector base and limit + * + * Returns: Nonzero if the two vectors are equal. + * + * Use: Performs an unsigned integer test for equality. + */ + +int mpx_ueq(const mpw *av, const mpw *avl, const mpw *bv, const mpw *bvl) +{ + MPX_SHRINK(av, avl); + MPX_SHRINK(bv, bvl); + if (avl - av != bvl - bv) + return (0); + while (av < avl) { + if (*av++ != *bv++) + return (0); + } + return (1); +} + /* --- @mpx_ucmp@ --- * * * Arguments: @const mpw *av, *avl@ = first argument vector base and limit @@ -453,7 +479,7 @@ int mpx_ucmp(const mpw *av, const mpw *avl, const mpw *bv, const mpw *bvl) } return (0); } - + /* --- @mpx_uadd@ --- * * * Arguments: @mpw *dv, *dvl@ = destination vector base and limit @@ -1070,7 +1096,7 @@ static int lsl(dstr *v) ALLOC(d, dl, al - a + (n + MPW_BITS - 1) / MPW_BITS); mpx_lsl(d, dl, a, al, n); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** lsl(%i) failed\n", n); dumpmp(" a", a, al); dumpmp("expected", c, cl); @@ -1095,7 +1121,7 @@ static int lsr(dstr *v) ALLOC(d, dl, al - a + (n + MPW_BITS - 1) / MPW_BITS + 1); mpx_lsr(d, dl, a, al, n); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** lsr(%i) failed\n", n); dumpmp(" a", a, al); dumpmp("expected", c, cl); @@ -1121,7 +1147,7 @@ static int uadd(dstr *v) ALLOC(d, dl, MAX(al - a, bl - b) + 1); mpx_uadd(d, dl, a, al, b, bl); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** uadd failed\n"); dumpmp(" a", a, al); dumpmp(" b", b, bl); @@ -1148,7 +1174,7 @@ static int usub(dstr *v) ALLOC(d, dl, al - a); mpx_usub(d, dl, a, al, b, bl); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** usub failed\n"); dumpmp(" a", a, al); dumpmp(" b", b, bl); @@ -1175,7 +1201,7 @@ static int umul(dstr *v) ALLOC(d, dl, (al - a) + (bl - b)); mpx_umul(d, dl, a, al, b, bl); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** umul failed\n"); dumpmp(" a", a, al); dumpmp(" b", b, bl); @@ -1200,7 +1226,7 @@ static int usqr(dstr *v) ALLOC(d, dl, 2 * (al - a)); mpx_usqr(d, dl, a, al); - if (MPX_UCMP(d, dl, !=, c, cl)) { + if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** usqr failed\n"); dumpmp(" a", a, al); dumpmp("expected", c, cl); @@ -1230,8 +1256,8 @@ static int udiv(dstr *v) ALLOC(s, sl, (bl - b) + 1); mpx_udiv(qq, qql, a, al, b, bl, s, sl); - if (MPX_UCMP(qq, qql, !=, q, ql) || - MPX_UCMP(a, al, !=, r, rl)) { + if (!mpx_ueq(qq, qql, q, ql) || + !mpx_ueq(a, al, r, rl)) { fprintf(stderr, "\n*** udiv failed\n"); dumpmp(" divisor", b, bl); dumpmp("expect r", r, rl); @@ -1263,7 +1289,6 @@ int main(int argc, char *argv[]) return (0); } - #endif /*----- That's all, folks -------------------------------------------------*/ diff --git a/mpx.h b/mpx.h index 076f14a..cb49bd4 100644 --- a/mpx.h +++ b/mpx.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mpx.h,v 1.9 1999/12/22 15:49:07 mdw Exp $ + * $Id: mpx.h,v 1.10 2000/10/08 12:06:12 mdw Exp $ * * Low level multiprecision arithmetic * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: mpx.h,v $ + * Revision 1.10 2000/10/08 12:06:12 mdw + * Provide @mpx_ueq@ for rapidly testing equality of two integers. + * * Revision 1.9 1999/12/22 15:49:07 mdw * New function for division by a small integer. * @@ -313,6 +316,19 @@ extern void mpx_lsr(mpw */*dv*/, mpw */*dvl*/, extern void mpx_2c(mpw */*dv*/, mpw */*dvl*/, const mpw */*v*/, const mpw */*vl*/); +/* --- @mpx_ueq@ --- * + * + * Arguments: @const mpw *av, *avl@ = first argument vector base and limit + * @const mpw *bv, *bvl@ = second argument vector base and limit + * + * Returns: Nonzero if the two vectors are equal. + * + * Use: Performs an unsigned integer test for equality. + */ + +extern int mpx_ueq(const mpw */*av*/, const mpw */*avl*/, + const mpw */*bv*/, const mpw */*bvl*/); + /* --- @mpx_ucmp@ --- * * * Arguments: @const mpw *av, *avl@ = first argument vector base and limit -- 2.11.0