|
Packit |
5c3484 |
/* Exercise mpf_get_ui.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
Copyright 2004 Free Software Foundation, Inc.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
This file is part of the GNU MP Library test suite.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
The GNU MP Library test suite is free software; you can redistribute it
|
|
Packit |
5c3484 |
and/or modify it under the terms of the GNU General Public License as
|
|
Packit |
5c3484 |
published by the Free Software Foundation; either version 3 of the License,
|
|
Packit |
5c3484 |
or (at your option) any later version.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
The GNU MP Library test suite is distributed in the hope that it will be
|
|
Packit |
5c3484 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5c3484 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit |
5c3484 |
Public License for more details.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
You should have received a copy of the GNU General Public License along with
|
|
Packit |
5c3484 |
the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
#include <stdio.h>
|
|
Packit |
5c3484 |
#include <stdlib.h>
|
|
Packit |
5c3484 |
#include "gmp.h"
|
|
Packit |
5c3484 |
#include "gmp-impl.h"
|
|
Packit |
5c3484 |
#include "tests.h"
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
void
|
|
Packit |
5c3484 |
check_limbdata (void)
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
#define M GMP_NUMB_MAX
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
static const struct {
|
|
Packit |
5c3484 |
mp_exp_t exp;
|
|
Packit |
5c3484 |
mp_size_t size;
|
|
Packit |
5c3484 |
mp_limb_t d[10];
|
|
Packit |
5c3484 |
unsigned long want;
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
} data[] = {
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
/* in the comments here, a "_" indicates a digit (ie. limb) position not
|
|
Packit |
5c3484 |
included in the d data, and therefore zero */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 0, 0, { 0 }, 0L }, /* 0 */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 1, 1, { 1 }, 1L }, /* 1 */
|
|
Packit |
5c3484 |
{ 1, -1, { 1 }, 1L }, /* -1 */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 0, 1, { 1 }, 0L }, /* .1 */
|
|
Packit |
5c3484 |
{ 0, -1, { 1 }, 0L }, /* -.1 */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ -1, 1, { 1 }, 0L }, /* ._1 */
|
|
Packit |
5c3484 |
{ -1, -1, { 1 }, 0L }, /* -._1 */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ -999, 1, { 1 }, 0L }, /* .___1 small */
|
|
Packit |
5c3484 |
{ MP_EXP_T_MIN, 1, { 1 }, 0L }, /* .____1 very small */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 999, 1, { 1 }, 0L }, /* 1____. big */
|
|
Packit |
5c3484 |
{ MP_EXP_T_MAX, 1, { 1 }, 0L }, /* 1_____. very big */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 1, 2, { 999, 2 }, 2L }, /* 2.9 */
|
|
Packit |
5c3484 |
{ 5, 8, { 7, 8, 9, 3, 0, 0, 0, 1 }, 3L }, /* 10003.987 */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 2, 2, { M, M }, ULONG_MAX }, /* FF. */
|
|
Packit |
5c3484 |
{ 2, 2, { M, M, M }, ULONG_MAX }, /* FF.F */
|
|
Packit |
5c3484 |
{ 3, 3, { M, M, M }, ULONG_MAX }, /* FFF. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
#if GMP_NUMB_BITS >= BITS_PER_ULONG
|
|
Packit |
5c3484 |
/* normal case, numb bigger than long */
|
|
Packit |
5c3484 |
{ 2, 1, { 1 }, 0L }, /* 1_. */
|
|
Packit |
5c3484 |
{ 2, 2, { 0, 1 }, 0L }, /* 10. */
|
|
Packit |
5c3484 |
{ 2, 2, { 999, 1 }, 999L }, /* 19. */
|
|
Packit |
5c3484 |
{ 3, 2, { 999, 1 }, 0L }, /* 19_. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
#else
|
|
Packit |
5c3484 |
/* nails case, numb smaller than long */
|
|
Packit |
5c3484 |
{ 2, 1, { 1 }, 1L << GMP_NUMB_BITS }, /* 1_. */
|
|
Packit |
5c3484 |
{ 3, 1, { 1 }, 0L }, /* 1__. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
{ 2, 2, { 99, 1 }, 99L + (1L << GMP_NUMB_BITS) }, /* 19. */
|
|
Packit |
5c3484 |
{ 3, 2, { 1, 99 }, 1L << GMP_NUMB_BITS }, /* 91_. */
|
|
Packit |
5c3484 |
{ 3, 3, { 0, 1, 99 }, 1L << GMP_NUMB_BITS }, /* 910. */
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
#endif
|
|
Packit |
5c3484 |
};
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mpf_t f;
|
|
Packit |
5c3484 |
unsigned long got;
|
|
Packit |
5c3484 |
int i;
|
|
Packit |
5c3484 |
mp_limb_t buf[20 + numberof(data[i].d)];
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
for (i = 0; i < numberof (data); i++)
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
refmpn_fill (buf, 10, CNST_LIMB(0xDEADBEEF));
|
|
Packit |
5c3484 |
refmpn_copy (buf+10, data[i].d, ABS(data[i].size));
|
|
Packit |
5c3484 |
refmpn_fill (buf+10+ABS(data[i].size), 10, CNST_LIMB(0xDEADBEEF));
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
PTR(f) = buf+10;
|
|
Packit |
5c3484 |
EXP(f) = data[i].exp;
|
|
Packit |
5c3484 |
SIZ(f) = data[i].size;
|
|
Packit |
5c3484 |
PREC(f) = numberof (data[i].d);
|
|
Packit |
5c3484 |
MPF_CHECK_FORMAT (f);
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
got = mpf_get_ui (f);
|
|
Packit |
5c3484 |
if (got != data[i].want)
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
printf ("mpf_get_ui wrong at limb data[%d]\n", i);
|
|
Packit |
5c3484 |
mpf_trace (" f", f);
|
|
Packit |
5c3484 |
mpn_trace (" d", data[i].d, data[i].size);
|
|
Packit |
5c3484 |
printf (" size %ld\n", (long) data[i].size);
|
|
Packit |
5c3484 |
printf (" exp %ld\n", (long) data[i].exp);
|
|
Packit |
5c3484 |
printf (" got %lu (0x%lX)\n", got, got);
|
|
Packit |
5c3484 |
printf (" want %lu (0x%lX)\n", data[i].want, data[i].want);
|
|
Packit |
5c3484 |
abort();
|
|
Packit |
5c3484 |
}
|
|
Packit |
5c3484 |
}
|
|
Packit |
5c3484 |
}
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
int
|
|
Packit |
5c3484 |
main (void)
|
|
Packit |
5c3484 |
{
|
|
Packit |
5c3484 |
tests_start ();
|
|
Packit |
5c3484 |
mp_trace_base = 16;
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
check_limbdata ();
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
tests_end ();
|
|
Packit |
5c3484 |
exit (0);
|
|
Packit |
5c3484 |
}
|