[BACK]Return to tconst_euler.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpfr / tests

Annotation of OpenXM_contrib/gmp/mpfr/tests/tconst_euler.c, Revision 1.1.1.1

1.1       ohara       1: /* Test file for mpfr_const_euler.
                      2:
                      3: Copyright 2001 Free Software Foundation.
                      4:
                      5: This file is part of the MPFR Library.
                      6:
                      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.
                     11:
                     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.
                     16:
                     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. */
                     21:
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24: #include "gmp.h"
                     25: #include "mpfr.h"
                     26: #include "mpfr-impl.h"
                     27:
                     28: int
                     29: main (int argc, char *argv[])
                     30: {
                     31:   mpfr_t gamma, y, z, t;
                     32:   unsigned int err, prec, yprec, p0 = 2, p1 = 200;
                     33:   mp_rnd_t rnd;
                     34:
                     35:   prec = (argc < 2) ? 53 : atoi(argv[1]);
                     36:
                     37:   if (argc > 1)
                     38:     {
                     39:       mpfr_init2 (gamma, prec);
                     40:       mpfr_const_euler (gamma, GMP_RNDN);
                     41:       printf("gamma="); mpfr_out_str (stdout, 10, 0, gamma, GMP_RNDD);
                     42:       putchar ('\n');
                     43:       mpfr_clear (gamma);
                     44:       return 0;
                     45:     }
                     46:
                     47:   mpfr_init (y);
                     48:   mpfr_init (z);
                     49:   mpfr_init (t);
                     50:
                     51:   for (prec = p0; prec <= p1; prec++)
                     52:     {
                     53:       mpfr_set_prec (z, prec);
                     54:       mpfr_set_prec (t, prec);
                     55:       yprec = prec + 10;
                     56:
                     57:       for (rnd=0; rnd<4; rnd++)
                     58:        {
                     59:          mpfr_set_prec (y, yprec);
                     60:          mpfr_const_euler (y, rnd);
                     61:          err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
                     62:          if (mpfr_can_round (y, err, rnd, rnd, prec))
                     63:            {
                     64:              mpfr_set (t, y, rnd);
                     65:              mpfr_const_euler (z, rnd);
                     66:              if (mpfr_cmp (t, z))
                     67:                {
                     68:                  printf ("results differ for prec=%u rnd_mode=%s\n", prec,
                     69:                          mpfr_print_rnd_mode (rnd));
                     70:                  printf ("   got      ");
                     71:                  mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
                     72:                  putchar ('\n');
                     73:                  printf ("   expected ");
                     74:                  mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
                     75:                  putchar ('\n');
                     76:                  printf ("   approximation was ");
                     77:                  mpfr_print_binary (y);
                     78:                  putchar ('\n');
                     79:                  exit (1);
                     80:                }
                     81:            }
                     82:        }
                     83:     }
                     84:
                     85:   mpfr_clear (y);
                     86:   mpfr_clear (z);
                     87:   mpfr_clear (t);
                     88:
                     89:   return 0;
                     90: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>