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

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

1.1     ! ohara       1: /* Tests of mpz_scan0 and mpz_scan1.
        !             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 "gmp.h"
        !            25: #include "gmp-impl.h"
        !            26: #include "tests.h"
        !            27:
        !            28:
        !            29: unsigned long
        !            30: refmpz_scan (mpz_srcptr z, unsigned long i, int sought)
        !            31: {
        !            32:   unsigned long  z_bits = (unsigned long) ABSIZ(z) * GMP_NUMB_BITS;
        !            33:
        !            34:   do
        !            35:     {
        !            36:       if (mpz_tstbit (z, i) == sought)
        !            37:         return i;
        !            38:       i++;
        !            39:     }
        !            40:   while (i <= z_bits);
        !            41:
        !            42:   return ULONG_MAX;
        !            43: }
        !            44:
        !            45: unsigned long
        !            46: refmpz_scan0 (mpz_srcptr z, unsigned long starting_bit)
        !            47: {
        !            48:   return refmpz_scan (z, starting_bit, 0);
        !            49: }
        !            50:
        !            51: unsigned long
        !            52: refmpz_scan1 (mpz_srcptr z, unsigned long starting_bit)
        !            53: {
        !            54:   return refmpz_scan (z, starting_bit, 1);
        !            55: }
        !            56:
        !            57:
        !            58: void
        !            59: check_ref (void)
        !            60: {
        !            61:   mpz_t          z;
        !            62:   int            test, size, neg, sought;
        !            63:   unsigned long  i, got, want;
        !            64:
        !            65:   mpz_init (z);
        !            66:   for (test = 0; test < 10; test++)
        !            67:     {
        !            68:       for (size = 0; size < 5; size++)
        !            69:         {
        !            70:           mpz_random2 (z, size);
        !            71:
        !            72:           for (neg = 0; neg <= 1; neg++)
        !            73:             {
        !            74:               if (neg)
        !            75:                 mpz_neg (z, z);
        !            76:
        !            77:               for (i = 0; i < size * GMP_NUMB_BITS + 8; i++)
        !            78:                 {
        !            79:                   for (sought = 0; sought <= 1; sought++)
        !            80:                     {
        !            81:                       if (sought == 0)
        !            82:                         {
        !            83:                           got = mpz_scan0 (z, i);
        !            84:                           want = refmpz_scan0 (z, i);
        !            85:                         }
        !            86:                       else
        !            87:                         {
        !            88:                           got = mpz_scan1 (z, i);
        !            89:                           want = refmpz_scan1 (z, i);
        !            90:                         }
        !            91:
        !            92:                       if (got != want)
        !            93:                         {
        !            94:                           printf ("wrong at test=%d, size=%d, neg=%d, i=%lu, sought=%d\n",
        !            95:                                   test, size, neg, i, sought);
        !            96:                           printf ("   z 0x");
        !            97:                           mpz_out_str (stdout, -16, z);
        !            98:                           printf ("\n");
        !            99:                           printf ("   got=%lu, want=%lu\n", got, want);
        !           100:                           exit (1);
        !           101:                         }
        !           102:                     }
        !           103:                 }
        !           104:             }
        !           105:         }
        !           106:     }
        !           107:   mpz_clear (z);
        !           108: }
        !           109:
        !           110:
        !           111: int
        !           112: main (int argc, char *argv[])
        !           113: {
        !           114:   tests_start ();
        !           115:
        !           116:   check_ref ();
        !           117:
        !           118:   tests_end ();
        !           119:   exit (0);
        !           120: }

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