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

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

1.1       ohara       1: /* Test file for mpfr_acos.
                      2:
                      3: Copyright 2001 Free Software Foundation.
                      4: Contributed by Mathieu Dutour.
                      5:
                      6: This file is part of the MPFR Library.
                      7:
                      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.
                     12:
                     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.
                     17:
                     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. */
                     22:
                     23: #include <stdio.h>
                     24: #include <stdlib.h>
                     25: #include "gmp.h"
                     26: #include "mpfr.h"
                     27: #include "mpfr-impl.h"
                     28: #include "mpfr-test.h"
                     29:
                     30: int
                     31: main (void)
                     32: {
                     33:   unsigned int prec, err, yprec, n;
                     34:   mp_rnd_t rnd;
                     35:   mpfr_t x, y, z;
                     36:
                     37:   mpfr_init (x);
                     38:   mpfr_init (y);
                     39:   mpfr_init (z);
                     40:
                     41:   MPFR_SET_NAN(x);
                     42:   mpfr_acos (y, x, GMP_RNDN);
                     43:   if (mpfr_nan_p(y) == 0)
                     44:     {
                     45:       fprintf (stderr, "Error: acos(NaN) != NaN\n");
                     46:       exit (1);
                     47:     }
                     48:
                     49:   mpfr_set_ui (x, 2, GMP_RNDN);
                     50:   mpfr_acos (y, x, GMP_RNDN);
                     51:   if (mpfr_nan_p(y) == 0)
                     52:     {
                     53:       fprintf (stderr, "Error: acos(2) != NaN\n");
                     54:       exit (1);
                     55:     }
                     56:
                     57:   for (prec = 2; prec <= 100; prec++)
                     58:     {
                     59:       mpfr_set_prec (x, prec);
                     60:       mpfr_set_prec (z, prec);
                     61:       yprec = prec + 10;
                     62:
                     63:       for (n=0; n<10; n++)
                     64:        {
                     65:          mpfr_random (x);
                     66:          rnd = random () % 4;
                     67:          mpfr_set_prec (y, yprec);
                     68:          mpfr_acos (y, x, rnd);
                     69:          err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
                     70:          if (mpfr_can_round (y, err, rnd, rnd, prec))
                     71:            {
                     72:              mpfr_round_prec (y, rnd, prec);
                     73:              mpfr_acos (z, x, rnd);
                     74:              if (mpfr_cmp (y, z))
                     75:                {
                     76:                  printf ("results differ for x=");
                     77:                  mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
                     78:                  printf (" prec=%u rnd_mode=%s\n", prec,
                     79:                          mpfr_print_rnd_mode (rnd));
                     80:                  printf ("   got ");
                     81:                  mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
                     82:                  putchar ('\n');
                     83:                  printf ("   expected ");
                     84:                  mpfr_out_str (stdout, 2, prec, y, GMP_RNDN);
                     85:                  putchar ('\n');
                     86:                }
                     87:            }
                     88:        }
                     89:     }
                     90:
                     91:   mpfr_clear (x);
                     92:   mpfr_clear (y);
                     93:   mpfr_clear (z);
                     94:
                     95:   return 0;
                     96: }

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