Upload Tizen:Base source
[external/gmp.git] / tests / t-gmpmax.c
1 /* Check the values of __GMP_UINT_MAX etc.
2
3 Copyright 2001 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 3 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.  If not, see http://www.gnu.org/licenses/.  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <limits.h>
23 #include "gmp.h"
24
25
26 /* __GMP_UINT_MAX etc are generated with expressions in gmp.h since we don't
27    want to demand <limits.h> or forcibly include it.  Check the expressions
28    come out the same as <limits.h>.  */
29
30 int
31 main (int argc, char *argv[])
32 {
33   int  error = 0;
34
35 #ifdef UINT_MAX
36   if (__GMP_UINT_MAX != UINT_MAX)
37     {
38       printf ("__GMP_UINT_MAX incorrect\n");
39       printf ("  __GMP_UINT_MAX  %u  0x%X\n", __GMP_UINT_MAX, __GMP_UINT_MAX);
40       printf ("  UINT_MAX        %u  0x%X\n", UINT_MAX, UINT_MAX);
41       error = 1;
42     }
43 #endif
44
45   /* gcc 2.95.2 limits.h on solaris 2.5.1 incorrectly selects a 64-bit
46      LONG_MAX, leading to some integer overflow in ULONG_MAX and a spurious
47      __GMP_ULONG_MAX != ULONG_MAX.  Casting ULONG_MAX to unsigned long is a
48      workaround.  */
49 #ifdef ULONG_MAX
50   if (__GMP_ULONG_MAX != (unsigned long) ULONG_MAX)
51     {
52       printf ("__GMP_ULONG_MAX incorrect\n");
53       printf ("  __GMP_ULONG_MAX  %lu  0x%lX\n", __GMP_ULONG_MAX, __GMP_ULONG_MAX);
54       printf ("  ULONG_MAX        %lu  0x%lX\n", ULONG_MAX, ULONG_MAX);
55       error = 1;
56     }
57 #endif
58
59 #ifdef USHRT_MAX
60   if (__GMP_USHRT_MAX != USHRT_MAX)
61     {
62       printf ("__GMP_USHRT_MAX incorrect\n");
63       printf ("  __GMP_USHRT_MAX  %hu  0x%hX\n", __GMP_USHRT_MAX, __GMP_USHRT_MAX);
64       printf ("  USHRT_MAX        %hu  0x%hX\n", USHRT_MAX, USHRT_MAX);
65       error = 1;
66     }
67 #endif
68
69   if (error)
70     abort ();
71
72   exit (0);
73 }