1
/* Test file for mpfr_set_z.
3
Copyright 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
This file is part of the MPFR Library.
7
The MPFR 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 MPFR 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 MPFR Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
20
MA 02110-1301, USA. */
27
#include "mpfr-test.h"
29
static void check0(void)
39
for(r = 0; r < GMP_RND_MAX; r++)
41
inexact = mpfr_set_z (x, y, (mp_rnd_t) r);
42
if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact)
44
printf("mpfr_set_z(x,0) failed for %s\n",
45
mpfr_print_rnd_mode ((mp_rnd_t) r));
53
/* FIXME: It'd be better to examine the actual data in an mpfr_t to see that
54
it's as expected. Comparing mpfr_set_z with mpfr_cmp or against
55
mpfr_get_si is a rather indirect test of a low level routine. */
58
check (long i, mp_rnd_t rnd)
63
mpfr_init2 (f, 8 * sizeof(long));
66
mpfr_set_z (f, z, rnd);
67
if (mpfr_get_si (f, GMP_RNDZ) != i)
69
printf ("Error in mpfr_set_z for i=%ld rnd_mode=%d\n", i, rnd);
87
mpz_set_str (z, "77031627725494291259359895954016675357279104942148788042", 10);
88
mpfr_set_z (x, z, GMP_RNDN);
89
mpfr_set_str_binary (y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186");
92
printf ("Error in mpfr_set_z on large input\n");
97
emax = mpfr_get_emax ();
99
mpz_set_str (z, "7", 10);
100
mpfr_set_z (x, z, GMP_RNDU);
101
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
103
mpfr_set_prec (x, 2);
104
mpz_set_str (z, "7", 10);
105
mpfr_set_z (x, z, GMP_RNDU);
106
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
109
/* check underflow */
110
emin = mpfr_get_emin ();
112
mpz_set_str (z, "1", 10);
113
mpfr_set_z (x, z, GMP_RNDZ);
114
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
116
mpfr_set_z (x, z, GMP_RNDN);
117
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
127
main (int argc, char *argv[])
135
for (j = 0; j < 200000; j++)
136
check (randlimb () & LONG_MAX, (mp_rnd_t) RND_RAND ());