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

Annotation of OpenXM_contrib/gmp/mpfr/tests/tasin.c, Revision 1.1

1.1     ! ohara       1: /* Test file for mpfr_asin.
        !             2:
        !             3: Copyright 2001, 2002 Free Software Foundation.
        !             4: Original version 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-test.h"
        !            28:
        !            29: int
        !            30: main (void)
        !            31: {
        !            32:   unsigned int prec, err, yprec, n;
        !            33:   mp_rnd_t rnd;
        !            34:   mpfr_t x, y, z;
        !            35:
        !            36:   mpfr_init (x);
        !            37:   mpfr_init (y);
        !            38:   mpfr_init (z);
        !            39:
        !            40:   /* check that sin(-1) = -Pi/2 */
        !            41:   mpfr_set_si (x, -1, GMP_RNDN);
        !            42:   mpfr_asin (y, x, GMP_RNDN);
        !            43:   mpfr_const_pi (z, GMP_RNDN);
        !            44:   mpfr_div_2exp (z, z, 1, GMP_RNDN);
        !            45:   mpfr_neg (z, z, GMP_RNDN);
        !            46:   if (mpfr_cmp (y, z))
        !            47:     {
        !            48:       fprintf (stderr, "sin(-1) is wrong, expected %.20e, got %.20e\n",
        !            49:                mpfr_get_d1 (z), mpfr_get_d1 (y));
        !            50:       exit (1);
        !            51:     }
        !            52:
        !            53:   for (prec = 2; prec <= 100; prec++)
        !            54:     {
        !            55:       mpfr_set_prec (x, prec);
        !            56:       mpfr_set_prec (z, prec);
        !            57:       yprec = prec + 10;
        !            58:
        !            59:       for (n = 0; n < 10; n++)
        !            60:        {
        !            61:          mpfr_random (x);
        !            62:          rnd = random () % 4;
        !            63:          mpfr_set_prec (y, yprec);
        !            64:          mpfr_asin (y, x, rnd);
        !            65:          err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
        !            66:          if (mpfr_can_round (y, err, rnd, rnd, prec))
        !            67:            {
        !            68:              mpfr_round_prec (y, rnd, prec);
        !            69:              mpfr_asin (z, x, rnd);
        !            70:              if (mpfr_cmp (y, z))
        !            71:                {
        !            72:                  printf ("results differ for x=");
        !            73:                  mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
        !            74:                  printf (" prec=%u rnd_mode=%s\n", prec,
        !            75:                          mpfr_print_rnd_mode (rnd));
        !            76:                  printf ("   got ");
        !            77:                  mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
        !            78:                  putchar ('\n');
        !            79:                  printf ("   expected ");
        !            80:                  mpfr_out_str (stdout, 2, prec, y, GMP_RNDN);
        !            81:                  putchar ('\n');
        !            82:                }
        !            83:            }
        !            84:        }
        !            85:     }
        !            86:
        !            87:   mpfr_clear (x);
        !            88:   mpfr_clear (y);
        !            89:   mpfr_clear (z);
        !            90:
        !            91:   return 0;
        !            92: }

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