1 /* Exercise mpf_get_ui.
3 Copyright 2004 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/. */
30 #define M GMP_NUMB_MAX
40 /* in the comments here, a "_" indicates a digit (ie. limb) position not
41 included in the d data, and therefore zero */
43 { 0, 0, { 0 }, 0L }, /* 0 */
45 { 1, 1, { 1 }, 1L }, /* 1 */
46 { 1, -1, { 1 }, 1L }, /* -1 */
48 { 0, 1, { 1 }, 0L }, /* .1 */
49 { 0, -1, { 1 }, 0L }, /* -.1 */
51 { -1, 1, { 1 }, 0L }, /* ._1 */
52 { -1, -1, { 1 }, 0L }, /* -._1 */
54 { -999, 1, { 1 }, 0L }, /* .___1 small */
55 { MP_EXP_T_MIN, 1, { 1 }, 0L }, /* .____1 very small */
57 { 999, 1, { 1 }, 0L }, /* 1____. big */
58 { MP_EXP_T_MAX, 1, { 1 }, 0L }, /* 1_____. very big */
60 { 1, 2, { 999, 2 }, 2L }, /* 2.9 */
61 { 5, 8, { 7, 8, 9, 3, 0, 0, 0, 1 }, 3L }, /* 10003.987 */
63 { 2, 2, { M, M }, ULONG_MAX }, /* FF. */
64 { 2, 2, { M, M, M }, ULONG_MAX }, /* FF.F */
65 { 3, 3, { M, M, M }, ULONG_MAX }, /* FFF. */
67 #if GMP_NUMB_BITS >= BITS_PER_ULONG
68 /* normal case, numb bigger than long */
69 { 2, 1, { 1 }, 0L }, /* 1_. */
70 { 2, 2, { 0, 1 }, 0L }, /* 10. */
71 { 2, 2, { 999, 1 }, 999L }, /* 19. */
72 { 3, 2, { 999, 1 }, 0L }, /* 19_. */
75 /* nails case, numb smaller than long */
76 { 2, 1, { 1 }, 1L << GMP_NUMB_BITS }, /* 1_. */
77 { 3, 1, { 1 }, 0L }, /* 1__. */
79 { 2, 2, { 99, 1 }, 99L + (1L << GMP_NUMB_BITS) }, /* 19. */
80 { 3, 2, { 1, 99 }, 1L << GMP_NUMB_BITS }, /* 91_. */
81 { 3, 3, { 0, 1, 99 }, 1L << GMP_NUMB_BITS }, /* 910. */
89 mp_limb_t buf[20 + numberof(data[i].d)];
91 for (i = 0; i < numberof (data); i++)
93 refmpn_fill (buf, 10, CNST_LIMB(0xDEADBEEF));
94 refmpn_copy (buf+10, data[i].d, ABS(data[i].size));
95 refmpn_fill (buf+10+ABS(data[i].size), 10, CNST_LIMB(0xDEADBEEF));
99 SIZ(f) = data[i].size;
100 PREC(f) = numberof (data[i].d);
101 MPF_CHECK_FORMAT (f);
103 got = mpf_get_ui (f);
104 if (got != data[i].want)
106 printf ("mpf_get_ui wrong at limb data[%d]\n", i);
108 mpn_trace (" d", data[i].d, data[i].size);
109 printf (" size %ld\n", (long) data[i].size);
110 printf (" exp %ld\n", (long) data[i].exp);
111 printf (" got %lu (0x%lX)\n", got, got);
112 printf (" want %lu (0x%lX)\n", data[i].want, data[i].want);