RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / share / doc / mpfr / examples / sample.c
blobfa76177d3ddb796d3ef22084888a56804b98ed46
1 /* This is the example given and commented on the MPFR web site:
2 * http://www.mpfr.org/sample.html
3 */
5 /*
6 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 Contributed by the Arenaire and Cacao projects, INRIA.
9 This file is part of the GNU MPFR Library.
11 The GNU MPFR Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MPFR Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
23 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <stdio.h>
29 #include <gmp.h>
30 #include <mpfr.h>
32 int main (void)
34 unsigned int i;
35 mpfr_t s, t, u;
37 mpfr_init2 (t, 200);
38 mpfr_set_d (t, 1.0, GMP_RNDD);
39 mpfr_init2 (s, 200);
40 mpfr_set_d (s, 1.0, GMP_RNDD);
41 mpfr_init2 (u, 200);
42 for (i = 1; i <= 100; i++)
44 mpfr_mul_ui (t, t, i, GMP_RNDU);
45 mpfr_set_d (u, 1.0, GMP_RNDD);
46 mpfr_div (u, u, t, GMP_RNDD);
47 mpfr_add (s, s, u, GMP_RNDD);
49 printf ("Sum is ");
50 mpfr_out_str (stdout, 10, 0, s, GMP_RNDD);
51 putchar ('\n');
52 mpfr_clear (s);
53 mpfr_clear (t);
54 mpfr_clear (u);
55 return 0;