1
/* Test file for mpfr_const_log2.
3
Copyright 1999, 2001 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., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
27
#include "mpfr-impl.h"
29
/* tlog2 [prec] [rnd] [0 = no print] */
31
void check _PROTO ((mp_prec_t, mp_prec_t));
34
check (mp_prec_t p0, mp_prec_t p1)
41
mpfr_init2 (z, p1 + 10);
42
mpfr_const_log2 (z, GMP_RNDN);
43
__mpfr_const_log2_prec = 1;
47
mpfr_set_prec (x, p0);
48
mpfr_set_prec (y, p0);
49
for (rnd = 0; rnd < 4; rnd++)
51
mpfr_const_log2 (x, rnd);
53
if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
56
fprintf (stderr, "mpfr_const_log2 fails for prec=%u, rnd=%s\n",
57
(unsigned int) p0, mpfr_print_rnd_mode (rnd));
58
fprintf (stderr, "expected ");
59
mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
60
fprintf (stderr, "\ngot ");
61
mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
62
fprintf (stderr, "\n");
74
main (int argc, char *argv[])
80
p = (argc>1) ? atoi(argv[1]) : 53;
81
rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ;
87
/* check precision of 2 bits */
89
mpfr_const_log2 (x, GMP_RNDN);
90
if (mpfr_get_d1 (x) != 0.75)
92
fprintf (stderr, "mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n");
93
fprintf (stderr, "expected 0.75, got %f\n", mpfr_get_d1 (x));
100
mpfr_const_log2 (x, rnd);
102
mpfr_out_str (stdout, 10, 0, x, rnd);
106
mpfr_set_prec (x, 53);
107
mpfr_const_log2 (x, rnd);
108
if (mpfr_get_d1 (x) != 6.9314718055994530941e-1)
110
fprintf (stderr, "mpfr_const_log2 failed for prec=53\n");