[BACK]Return to t-modlinv.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / tests

Annotation of OpenXM_contrib/gmp/tests/t-modlinv.c, Revision 1.1

1.1     ! ohara       1: /* Test modlimb_invert.
        !             2:
        !             3: Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
        !             4:
        !             5: This file is part of the GNU MP Library.
        !             6:
        !             7: The GNU MP Library is free software; you can redistribute it and/or modify
        !             8: it under the terms of the GNU Lesser General Public License as published by
        !             9: the Free Software Foundation; either version 2.1 of the License, or (at your
        !            10: option) any later version.
        !            11:
        !            12: The GNU MP Library is distributed in the hope that it will be useful, but
        !            13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
        !            15: License for more details.
        !            16:
        !            17: You should have received a copy of the GNU Lesser General Public License
        !            18: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
        !            19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
        !            20: MA 02111-1307, USA. */
        !            21:
        !            22: #include <stdio.h>
        !            23: #include <stdlib.h>
        !            24: #include <string.h>
        !            25: #include "gmp.h"
        !            26: #include "gmp-impl.h"
        !            27: #include "longlong.h"
        !            28: #include "tests.h"
        !            29:
        !            30:
        !            31: void
        !            32: one (mp_limb_t n)
        !            33: {
        !            34:   mp_limb_t  inv, prod;
        !            35:
        !            36:   modlimb_invert (inv, n);
        !            37:   prod = (inv * n) & GMP_NUMB_MASK;
        !            38:   if (prod != 1)
        !            39:     {
        !            40:       printf ("modlimb_invert wrong on n=0x%lX, got 0x%lX, product 0x%lX\n",
        !            41:               n, inv, prod);
        !            42:       abort ();
        !            43:     }
        !            44: }
        !            45:
        !            46: void
        !            47: some (void)
        !            48: {
        !            49:   int  i;
        !            50:   for (i = 0; i < 10000; i++)
        !            51:     one (refmpn_random_limb () | 1);
        !            52: }
        !            53:
        !            54: void
        !            55: all (void)
        !            56: {
        !            57:   mp_limb_t  n;
        !            58:
        !            59:   n = 1;
        !            60:   do {
        !            61:     one (n);
        !            62:     n += 2;
        !            63:   } while (n != 1);
        !            64: }
        !            65:
        !            66:
        !            67: int
        !            68: main (int argc, char *argv[])
        !            69: {
        !            70:   tests_start ();
        !            71:
        !            72:   if (argc >= 2 && strcmp (argv[1], "-a") == 0)
        !            73:     {
        !            74:       /* it's feasible to run all values on a 32-bit limb, but not a 64-bit */
        !            75:       all ();
        !            76:     }
        !            77:   else
        !            78:     {
        !            79:       some ();
        !            80:     }
        !            81:
        !            82:   tests_end ();
        !            83:   exit (0);
        !            84: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>