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

Annotation of OpenXM_contrib/gmp/mpz/tests/t-2exp.c, Revision 1.1

1.1     ! maekawa     1: /* Test mpz_ui_pow_ui, mpz_fdiv_q, mpz_fdiv_q_2exp, mpz_fdiv_r,
        !             2:    mpz_fdiv_r_2exp, and mpz_mul_2exp.
        !             3:
        !             4: Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
        !             5:
        !             6: This file is part of the GNU MP Library.
        !             7:
        !             8: The GNU MP Library is free software; you can redistribute it and/or modify
        !             9: it under the terms of the GNU Lesser General Public License as published by
        !            10: the Free Software Foundation; either version 2.1 of the License, or (at your
        !            11: option) any later version.
        !            12:
        !            13: The GNU MP Library is distributed in the hope that it will be useful, but
        !            14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            15: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
        !            16: License for more details.
        !            17:
        !            18: You should have received a copy of the GNU Lesser General Public License
        !            19: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
        !            20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
        !            21: MA 02111-1307, USA. */
        !            22:
        !            23: #include <stdio.h>
        !            24: #include "gmp.h"
        !            25: #include "gmp-impl.h"
        !            26: #include "longlong.h"
        !            27: #include "urandom.h"
        !            28:
        !            29: #ifndef SIZE
        !            30: #define SIZE 8
        !            31: #endif
        !            32:
        !            33: main (argc, argv)
        !            34:      int argc;
        !            35:      char **argv;
        !            36: {
        !            37:   mpz_t x, r1, r2, q1, q2, d, t;
        !            38:   unsigned long int c;
        !            39:   int test;
        !            40:   int ntests = 100000;
        !            41:
        !            42:   if (argc == 2)
        !            43:      ntests = atoi (argv[1]);
        !            44:
        !            45:   mpz_init (x);
        !            46:   mpz_init (q1);
        !            47:   mpz_init (q2);
        !            48:   mpz_init (r1);
        !            49:   mpz_init (r2);
        !            50:   mpz_init (d);
        !            51:   mpz_init (t);
        !            52:
        !            53:   for (test = 1; test <= ntests; test++)
        !            54:     {
        !            55:       mpz_random2 (x, urandom () % (2 * SIZE) - SIZE);
        !            56:       c = urandom () % (3 * SIZE / 2 * BITS_PER_MP_LIMB);
        !            57:       mpz_ui_pow_ui (d, (unsigned long) 2, c);
        !            58:
        !            59:       mpz_fdiv_q (q1, x, d);
        !            60:       mpz_fdiv_q_2exp (q2, x, c);
        !            61:       mpz_fdiv_r (r1, x, d);
        !            62:       mpz_fdiv_r_2exp (r2, x, c);
        !            63:
        !            64:       if (mpz_cmp (q1, q2) != 0 || mpz_cmp (r1, r2) != 0)
        !            65:        abort ();
        !            66:
        !            67:       mpz_mul_2exp (t, q1, c);
        !            68:       mpz_add (t, t, r1);
        !            69:       if (mpz_cmp (t, x) != 0)
        !            70:        abort ();
        !            71:
        !            72:       if (mpz_cmp (r1, d) >= 0)
        !            73:        abort ();
        !            74:     }
        !            75:
        !            76:   exit (0);
        !            77: }

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