GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / share / doc / mpfr / examples / divworst.c
blobc7eecb8410cb0748c86188fff8e21b98bbdfe9b9
1 /* Test of the double rounding effect.
3 * This example was presented at the CNC'2 summer school on MPFR and MPC
4 * at LORIA, Nancy, France.
6 * Arguments: max difference of exponents dmax, significand size n.
7 * Optional argument: extended precision p (with double rounding).
9 * Return all the couples of positive machine numbers (x,y) such that
10 * 1/2 <= y < 1, 0 <= Ex - Ey <= dmax, x - y is exactly representable
11 * in precision n and the results of floor(x/y) in the rounding modes
12 * toward 0 and to nearest are different.
16 Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
17 Contributed by the Arenaire and Cacao projects, INRIA.
19 This file is part of the GNU MPFR Library.
21 The GNU MPFR Library is free software; you can redistribute it and/or modify
22 it under the terms of the GNU Lesser General Public License as published by
23 the Free Software Foundation; either version 3 of the License, or (at your
24 option) any later version.
26 The GNU MPFR Library is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
29 License for more details.
31 You should have received a copy of the GNU Lesser General Public License
32 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
33 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
34 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <mpfr.h>
41 #define PRECN x, y, z
42 #define VARS PRECN, t
44 static unsigned long
45 eval (mpfr_t x, mpfr_t y, mpfr_t z, mpfr_t t, mpfr_rnd_t rnd)
47 mpfr_div (t, x, y, rnd); /* the division x/y in precision p */
48 mpfr_set (z, t, rnd); /* the rounding to the precision n */
49 mpfr_rint_floor (z, z, rnd);
50 return mpfr_get_ui (z, rnd);
53 int main (int argc, char *argv[])
55 int dmax, n, p;
56 mpfr_t VARS;
58 if (argc != 3 && argc != 4)
60 fprintf (stderr, "Usage: divworst <dmax> <n> [ <p> ]\n");
61 exit (EXIT_FAILURE);
64 dmax = atoi (argv[1]);
65 n = atoi (argv[2]);
66 p = argc == 3 ? n : atoi (argv[3]);
67 if (p < n)
69 fprintf (stderr, "divworst: p must be greater or equal to n\n");
70 exit (EXIT_FAILURE);
73 mpfr_inits2 (n, PRECN, (mpfr_ptr) 0);
74 mpfr_init2 (t, p);
76 for (mpfr_set_ui_2exp (x, 1, -1, GMP_RNDN);
77 mpfr_get_exp (x) <= dmax;
78 mpfr_nextabove (x))
79 for (mpfr_set_ui_2exp (y, 1, -1, GMP_RNDN);
80 mpfr_get_exp (y) == 0;
81 mpfr_nextabove (y))
83 unsigned long rz, rn;
85 if (mpfr_sub (z, x, y, GMP_RNDZ) != 0)
86 continue; /* x - y is not representable in precision n */
87 rz = eval (x, y, z, t, GMP_RNDZ);
88 rn = eval (x, y, z, t, GMP_RNDN);
89 if (rz == rn)
90 continue;
91 mpfr_printf ("x = %.*Rb ; y = %.*Rb ; Z: %lu ; N: %lu\n",
92 n - 1, x, n - 1, y, rz, rn);
95 mpfr_clears (VARS, (mpfr_ptr) 0);
96 return 0;