1
/* Test file for mpfr_const_log2.
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. */
25
#include "mpfr-test.h"
27
/* tlog2 [prec] [rnd] [0 = no print] */
30
check (mp_prec_t p0, mp_prec_t p1)
38
mpfr_init2 (z, p1 + 10);
39
mpfr_const_log2 (z, GMP_RNDN);
40
mpfr_clear_cache (__gmpfr_cache_const_log2);
44
mpfr_set_prec (x, p0);
45
mpfr_set_prec (y, p0);
47
rnd = (mp_rnd_t) RND_RAND ();
48
mpfr_const_log2 (x, rnd);
50
if ((dif = mpfr_cmp (x, y))
51
&& mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
54
printf ("mpfr_const_log2 fails for prec=%u, rnd=%s Diff=%d\n",
55
(unsigned int) p0, mpfr_print_rnd_mode (rnd), dif);
56
printf ("expected "), mpfr_dump (y);
57
printf ("got "), mpfr_dump (x);
72
mpfr_init2 (x, 25000);
73
mpfr_init2 (y, 26000);
74
(mpfr_const_log2) (x, GMP_RNDN); /* First one ! */
75
(mpfr_const_log2) (y, GMP_RNDN); /* Then the other - cache - */
76
mpfr_prec_round (y, 25000, GMP_RNDN);
79
printf ("const_log2: error for large prec\n");
83
/* worst-case with 15 successive ones after last bit,
84
to exercise can_round loop */
85
mpfr_set_prec (x, 26249);
86
mpfr_const_log2 (x, GMP_RNDZ);
88
mpfr_clears (x, y, NULL);
99
i = mpfr_const_log2 (x, GMP_RNDN);
102
printf("Error for log2. Invalid ternary value (1).\n");
105
mpfr_set_prec (x, 194);
106
i = mpfr_const_log2 (x, GMP_RNDN);
109
printf("Error for log2. Invalid ternary value (2).\n");
114
mpfr_set_prec (x, 9);
115
mpfr_const_log2 (x, GMP_RNDN);
116
mpfr_set_prec (x, 8);
117
mpfr_const_log2 (x, GMP_RNDN);
118
if (mpfr_cmp_str (x, "0.10110001E0", 2, GMP_RNDN))
120
printf("Error for log2. Wrong rounding.\n");
128
main (int argc, char *argv[])
136
p = (argc>1) ? atoi(argv[1]) : 53;
137
rnd = (argc>2) ? (mp_rnd_t) atoi(argv[2]) : GMP_RNDZ;
143
/* check precision of 2 bits */
144
mpfr_set_prec (x, 2);
145
mpfr_const_log2 (x, GMP_RNDN);
146
if (mpfr_cmp_ui_2exp(x, 3, -2)) /* 3*2^-2 */
148
printf ("mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n"
149
"expected 0.75, got ");
150
mpfr_out_str(stdout, 10, 0, x, GMP_RNDN);
157
mpfr_set_prec (x, p);
158
mpfr_const_log2 (x, rnd);
160
mpfr_out_str (stdout, 10, 0, x, rnd);
164
mpfr_set_prec (x, 53);
165
mpfr_const_log2 (x, GMP_RNDZ);
166
if (mpfr_cmp_str1 (x, "6.9314718055994530941e-1") )
168
printf ("mpfr_const_log2 failed for prec=53\n");
172
mpfr_set_prec (x, 32);
173
mpfr_const_log2 (x, GMP_RNDN);
174
if (mpfr_cmp_str1 (x, "0.69314718060195446"))
176
printf ("mpfr_const_log2 failed for prec=32\n");