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 2.1 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; 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. */
42
{ 10, "12345", 12345L },
43
{ 10, "-12345", -12345L },
45
/* fraction bits ignored */
52
{ 16, "1.000000000000000000000000000000000000000000000000001", 1L },
53
{ 16, "-1.000000000000000000000000000000000000000000000000001", -1L },
55
/* low bits extracted (this is undocumented) */
56
{ 16, "1000000000000000000000000000000000000000000000000001", 1L },
57
{ 16, "-1000000000000000000000000000000000000000000000000001", -1L },
65
for (i = 0; i < numberof (data); i++)
67
mpf_set_str_or_abort (f, data[i].f, data[i].base);
70
if (got != data[i].want)
72
printf ("mpf_get_si wrong at data[%d]\n", i);
73
printf (" f \"%s\"\n", data[i].f);
74
printf (" dec "); mpf_out_str (stdout, 10, 0, f); printf ("\n");
75
printf (" hex "); mpf_out_str (stdout, 16, 0, f); printf ("\n");
76
printf (" got %ld (0x%lX)\n", got, got);
77
printf (" want %ld (0x%lX)\n", data[i].want, data[i].want);
94
#define CHECK_MAX(name) \
97
printf ("mpf_get_si wrong on %s\n", name); \
99
mpf_out_str (stdout, 10, 0, f); printf (", hex "); \
100
mpf_out_str (stdout, 16, 0, f); printf ("\n"); \
101
printf (" got %ld, hex %lX\n", got, got); \
102
printf (" want %ld, hex %lX\n", want, want); \
107
mpf_set_si (f, want);
108
got = mpf_get_si (f);
109
CHECK_MAX ("LONG_MAX");
112
mpf_set_si (f, want);
113
got = mpf_get_si (f);
114
CHECK_MAX ("LONG_MIN");