source: trunk/third/gmp/tests/mpz/t-gcd_ui.c @ 22254

Revision 22254, 1.6 KB checked in by ghudson, 19 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r22253, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test mpz_gcd_ui.
2
3Copyright 2003 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 02111-1307, USA. */
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include "gmp.h"
26#include "gmp-impl.h"
27#include "tests.h"
28
29/* Check mpz_gcd_ui doesn't try to return a value out of range.
30   This was wrong in gmp 4.1.2 with a long long limb.  */
31static void
32check_ui_range (void)
33{
34  unsigned long  got;
35  mpz_t  x;
36  int  i;
37
38  mpz_init_set_ui (x, ULONG_MAX);
39
40  for (i = 0; i < 20; i++)
41    {
42      mpz_mul_2exp (x, x, 1L);
43      got = mpz_gcd_ui (NULL, x, 0L);
44      if (got != 0)
45        {
46          printf ("mpz_gcd_ui (ULONG_MAX*2^%d, 0)\n", i);
47          printf ("   return %#lx\n", got);
48          printf ("   should be 0\n");
49          abort ();
50        }
51    }
52
53  mpz_clear (x);
54}
55
56int
57main (void)
58{
59  tests_start ();
60
61  check_ui_range ();
62
63  tests_end ();
64  exit (0);
65}
Note: See TracBrowser for help on using the repository browser.