1
/* Test file for mpfr_ui_pow.
3
Copyright 2001 Free Software Foundation.
4
Adapted from tarctan.c.
6
This file is part of the MPFR Library.
8
The MPFR Library is free software; you can redistribute it and/or modify
9
it under the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation; either version 2.1 of the License, or (at your
11
option) any later version.
13
The MPFR Library is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16
License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with the MPFR Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21
MA 02111-1307, USA. */
28
#include "mpfr-impl.h"
29
#include "mpfr-test.h"
33
main (int argc, char *argv[])
45
mpfr_ui_pow (y, n, x, GMP_RNDN);
48
printf ("evaluation of function in INF does not return INF\n");
53
mpfr_ui_pow (y, n,x, GMP_RNDN);
56
printf ("evaluation of function in -INF does not return 0");
61
mpfr_ui_pow (y, n,x, GMP_RNDN);
64
printf ("evaluation of function in NAN does not return NAN");
69
mp_prec_t prec, yprec;
72
int inexact, compare, compare2;
83
for (prec = p0; prec <= p1; prec++)
85
mpfr_set_prec (x, prec);
86
mpfr_set_prec (z, prec);
87
mpfr_set_prec (t, prec);
96
mpfr_set_prec (y, yprec);
97
compare = mpfr_ui_pow (y, nt, x, rnd);
98
err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
99
if (mpfr_can_round (y, err, rnd, rnd, prec))
101
mpfr_set (t, y, rnd);
102
inexact = mpfr_ui_pow (z, nt, x, rnd);
105
printf ("results differ for x=");
106
mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
107
printf (" n= %i",nt);
108
printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
109
mpfr_print_rnd_mode (rnd));
111
mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
113
printf ("expected ");
114
mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
117
mpfr_print_binary (y);
121
compare2 = mpfr_cmp (t, y);
122
/* if rounding to nearest, cannot know the sign of t - f(x)
123
because of composed rounding: y = o(f(x)) and t = o(y) */
124
if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
125
compare = compare + compare2;
127
compare = inexact; /* cannot determine sign(t-f(x)) */
128
if (((inexact == 0) && (compare != 0)) ||
129
((inexact > 0) && (compare <= 0)) ||
130
((inexact < 0) && (compare >= 0)))
132
fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
133
mpfr_print_rnd_mode (rnd), compare, inexact);
134
printf ("x="); mpfr_print_binary (x); putchar ('\n');
135
printf ("y="); mpfr_print_binary (y); putchar ('\n');
136
printf ("t="); mpfr_print_binary (t); putchar ('\n');