1 /* Exercise mpz_get_si.
3 Copyright 2000, 2001 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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.
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.
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/. */
40 { "-12345", -12345L },
48 for (i = 0; i < numberof (data); i++)
50 mpz_set_str_or_abort (n, data[i].n, 0);
53 if (got != data[i].want)
55 printf ("mpz_get_si wrong at data[%d]\n", i);
56 printf (" n \"%s\" (", data[i].n);
57 mpz_out_str (stdout, 10, n); printf (", hex ");
58 mpz_out_str (stdout, 16, n); printf (")\n");
59 printf (" got %ld (0x%lX)\n", got, got);
60 printf (" want %ld (0x%lX)\n", data[i].want, data[i].want);
77 #define CHECK_MAX(name) \
80 printf ("mpz_get_si wrong on %s\n", name); \
82 mpz_out_str (stdout, 10, n); printf (", hex "); \
83 mpz_out_str (stdout, 16, n); printf ("\n"); \
84 printf (" got %ld, hex %lX\n", got, got); \
85 printf (" want %ld, hex %lX\n", want, want); \
92 CHECK_MAX ("LONG_MAX");
97 CHECK_MAX ("LONG_MIN");
99 /* The following checks that -0x100000000 gives -0x80000000. This doesn't
100 actually fit in a long and the result from mpz_get_si() is undefined,
101 but -0x80000000 is what comes out currently, and it should be that
102 value irrespective of the mp_limb_t size (long or long long). */
105 mpz_mul_2exp (n, n, 1);
106 CHECK_MAX ("-0x100...00");