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

Annotation of OpenXM_contrib/gmp/tests/mpz/t-divis_2exp.c, Revision 1.1.1.1

1.1       ohara       1: /* test mpz_divisible_2exp_p */
                      2:
                      3: /*
                      4: Copyright 2001 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:
                     24: #include <stdio.h>
                     25: #include <stdlib.h>
                     26:
                     27: #include "gmp.h"
                     28: #include "gmp-impl.h"
                     29: #include "tests.h"
                     30:
                     31:
                     32: void
                     33: check_one (mpz_srcptr a, unsigned long d, int want)
                     34: {
                     35:   int   got;
                     36:
                     37:   got = (mpz_divisible_2exp_p (a, d) != 0);
                     38:   if (want != got)
                     39:     {
                     40:       printf ("mpz_divisible_2exp_p wrong\n");
                     41:       printf ("   expected %d got %d\n", want, got);
                     42:       mpz_trace ("   a", a);
                     43:       printf    ("   d=%lu\n", d);
                     44:       mp_trace_base = -16;
                     45:       mpz_trace ("   a", a);
                     46:       printf    ("   d=0x%lX\n", d);
                     47:       abort ();
                     48:     }
                     49: }
                     50:
                     51: void
                     52: check_data (void)
                     53: {
                     54:   static const struct {
                     55:     const char    *a;
                     56:     unsigned long d;
                     57:     int           want;
                     58:
                     59:   } data[] = {
                     60:
                     61:     { "0", 0, 1 },
                     62:     { "0", 1, 1 },
                     63:     { "0", 2, 1 },
                     64:     { "0", 3, 1 },
                     65:
                     66:     { "1", 0, 1 },
                     67:     { "1", 1, 0 },
                     68:     { "1", 2, 0 },
                     69:     { "1", 3, 0 },
                     70:     { "1", 10000, 0 },
                     71:
                     72:     { "4", 0, 1 },
                     73:     { "4", 1, 1 },
                     74:     { "4", 2, 1 },
                     75:     { "4", 3, 0 },
                     76:     { "4", 4, 0 },
                     77:     { "4", 10000, 0 },
                     78:
                     79:     { "0x80000000", 31, 1 },
                     80:     { "0x80000000", 32, 0 },
                     81:     { "0x80000000", 64, 0 },
                     82:
                     83:     { "0x100000000", 32, 1 },
                     84:     { "0x100000000", 33, 0 },
                     85:     { "0x100000000", 64, 0 },
                     86:
                     87:     { "0x8000000000000000", 63, 1 },
                     88:     { "0x8000000000000000", 64, 0 },
                     89:     { "0x8000000000000000", 128, 0 },
                     90:
                     91:     { "0x10000000000000000", 64, 1 },
                     92:     { "0x10000000000000000", 65, 0 },
                     93:     { "0x10000000000000000", 128, 0 },
                     94:     { "0x10000000000000000", 256, 0 },
                     95:
                     96:     { "0x10000000000000000100000000", 32, 1 },
                     97:     { "0x10000000000000000100000000", 33, 0 },
                     98:     { "0x10000000000000000100000000", 64, 0 },
                     99:
                    100:     { "0x1000000000000000010000000000000000", 64, 1 },
                    101:     { "0x1000000000000000010000000000000000", 65, 0 },
                    102:     { "0x1000000000000000010000000000000000", 128, 0 },
                    103:     { "0x1000000000000000010000000000000000", 256, 0 },
                    104:     { "0x1000000000000000010000000000000000", 1024, 0 },
                    105:
                    106:   };
                    107:
                    108:   mpz_t   a, d;
                    109:   int     i;
                    110:
                    111:   mpz_init (a);
                    112:   mpz_init (d);
                    113:
                    114:   for (i = 0; i < numberof (data); i++)
                    115:     {
                    116:       mpz_set_str_or_abort (a, data[i].a, 0);
                    117:       check_one (a, data[i].d, data[i].want);
                    118:
                    119:       mpz_neg (a, a);
                    120:       check_one (a, data[i].d, data[i].want);
                    121:     }
                    122:
                    123:   mpz_clear (a);
                    124:   mpz_clear (d);
                    125: }
                    126:
                    127: int
                    128: main (int argc, char *argv[])
                    129: {
                    130:   tests_start ();
                    131:
                    132:   check_data ();
                    133:
                    134:   tests_end ();
                    135:   exit (0);
                    136: }

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