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

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

1.1       ohara       1: /* Test file for mpfr_sin.
                      2:
                      3: Copyright 2001, 2002 Free Software Foundation, Inc.
                      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 <math.h>
                     25: #include "gmp.h"
                     26: #include "mpfr.h"
                     27: #include "mpfr-impl.h"
                     28: #include "mpfr-test.h"
                     29:
                     30: void check53 _PROTO ((double, double, mp_rnd_t));
                     31:
                     32: void
                     33: check53 (double x, double sin_x, mp_rnd_t rnd_mode)
                     34: {
                     35:   mpfr_t xx, s;
                     36:
                     37:   mpfr_init2 (xx, 53);
                     38:   mpfr_init2 (s, 53);
                     39:   mpfr_set_d (xx, x, rnd_mode); /* should be exact */
                     40:   mpfr_sin (s, xx, rnd_mode);
                     41:   if (mpfr_get_d1 (s) != sin_x && (!isnan(sin_x) || !mpfr_nan_p(s)))
                     42:     {
                     43:       fprintf (stderr, "mpfr_sin failed for x=%1.20e, rnd=%s\n", x,
                     44:               mpfr_print_rnd_mode (rnd_mode));
                     45:       fprintf (stderr, "mpfr_sin gives sin(x)=%1.20e, expected %1.20e\n",
                     46:               mpfr_get_d1 (s), sin_x);
                     47:       exit(1);
                     48:     }
                     49:   mpfr_clear (xx);
                     50:   mpfr_clear (s);
                     51: }
                     52:
                     53: #define TEST_FUNCTION mpfr_sin
                     54: #include "tgeneric.c"
                     55:
                     56: int
                     57: main (int argc, char *argv[])
                     58: {
                     59:   mpfr_t x;
                     60:
                     61: #ifdef HAVE_INFS
                     62:   check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
                     63:   check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
                     64:   check53 (DBL_NEG_INF, DBL_NAN, GMP_RNDN);
                     65: #endif
                     66:   /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
                     67:   check53 (4.984987858808754279e-1, 4.781075595393330379e-1, GMP_RNDN);
                     68:   check53 (4.984987858808754279e-1, 4.781075595393329824e-1, GMP_RNDD);
                     69:   check53 (4.984987858808754279e-1, 4.781075595393329824e-1, GMP_RNDZ);
                     70:   check53 (4.984987858808754279e-1, 4.781075595393330379e-1, GMP_RNDU);
                     71:   check53 (1.00031274099908640274,  8.416399183372403892e-1, GMP_RNDN);
                     72:   check53 (1.00229256850978698523,  8.427074524447979442e-1, GMP_RNDZ);
                     73:   check53 (1.00288304857059840103,  8.430252033025980029e-1, GMP_RNDZ);
                     74:   check53 (1.00591265847407274059,  8.446508805292128885e-1, GMP_RNDN);
                     75:
                     76:   check53 (1.00591265847407274059,  8.446508805292128885e-1, GMP_RNDN);
                     77:
                     78:   mpfr_init2 (x, 2);
                     79:
                     80:   mpfr_set_d (x, 0.5, GMP_RNDN);
                     81:   mpfr_sin (x, x, GMP_RNDD);
                     82:   if (mpfr_get_d1 (x) != 0.375)
                     83:     {
                     84:       fprintf (stderr, "mpfr_sin(0.5, GMP_RNDD) failed with precision=2\n");
                     85:       exit (1);
                     86:     }
                     87:
                     88:   /* bug found by Kevin Ryde */
                     89:   mpfr_const_pi (x, GMP_RNDN);
                     90:   mpfr_mul_ui (x, x, 3L, GMP_RNDN);
                     91:   mpfr_div_ui (x, x, 2L, GMP_RNDN);
                     92:   mpfr_sin (x, x, GMP_RNDN);
                     93:   if (mpfr_cmp_ui (x, 0) >= 0)
                     94:     {
                     95:       fprintf (stderr, "Error: wrong sign for sin(3*Pi/2)\n");
                     96:       exit (1);
                     97:     }
                     98:
                     99:   mpfr_clear (x);
                    100:
                    101:   test_generic (2, 100, 80);
                    102:
                    103:   return 0;
                    104: }

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