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

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

1.1       ohara       1: /* Test file for mpfr_cos.
                      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 cos_x, mp_rnd_t rnd_mode)
                     34: {
                     35:   mpfr_t xx, c;
                     36:
                     37:   mpfr_init2 (xx, 53);
                     38:   mpfr_init2 (c, 53);
                     39:   mpfr_set_d (xx, x, rnd_mode); /* should be exact */
                     40:   mpfr_cos (c, xx, rnd_mode);
                     41:   if (mpfr_get_d1 (c) != cos_x && (!isnan(cos_x) || !mpfr_nan_p(c)))
                     42:     {
                     43:       fprintf (stderr, "mpfr_cos failed for x=%1.20e, rnd=%s\n", x,
                     44:               mpfr_print_rnd_mode (rnd_mode));
                     45:       fprintf (stderr, "mpfr_cos gives cos(x)=%1.20e, expected %1.20e\n",
                     46:               mpfr_get_d1 (c), cos_x);
                     47:       exit (1);
                     48:     }
                     49:   mpfr_clear (xx);
                     50:   mpfr_clear (c);
                     51: }
                     52:
                     53: #define TEST_FUNCTION mpfr_cos
                     54: #include "tgeneric.c"
                     55:
                     56: int
                     57: main (int argc, char *argv[])
                     58: {
                     59:   mpfr_t x, y;
                     60:
                     61:   mpfr_init (x);
                     62:   mpfr_init (y);
                     63:
                     64:   mpfr_set_prec (x, 53);
                     65:   mpfr_set_prec (y, 2);
                     66:   mpfr_set_d (x, 9.81333845856942e-1, GMP_RNDN);
                     67:   mpfr_cos (y, x, GMP_RNDN);
                     68:
                     69:   mpfr_set_prec (x, 30);
                     70:   mpfr_set_prec (y, 30);
                     71:   mpfr_set_str_raw (x, "1.00001010001101110010100010101e-1");
                     72:   mpfr_cos (y, x, GMP_RNDU);
                     73:   mpfr_set_str_raw (x, "1.10111100010101011110101010100e-1");
                     74:   if (mpfr_cmp (y, x))
                     75:     {
                     76:       fprintf (stderr, "Error for prec=30, rnd=GMP_RNDU\n");
                     77:       printf ("expected "); mpfr_print_binary (x); putchar ('\n');
                     78:       printf ("     got "); mpfr_print_binary (y); putchar ('\n');
                     79:       exit (1);
                     80:     }
                     81:
                     82:   mpfr_set_prec (x, 59);
                     83:   mpfr_set_prec (y, 59);
                     84:   mpfr_set_str_raw (x, "1.01101011101111010011111110111111111011011101100111100011e-3");
                     85:   mpfr_cos (y, x, GMP_RNDU);
                     86:   mpfr_set_str_raw (x, "1.1111011111110010001001001011100111101110100010000010010011e-1");
                     87:   if (mpfr_cmp (y, x))
                     88:     {
                     89:       fprintf (stderr, "Error for prec=59, rnd=GMP_RNDU\n");
                     90:       printf ("expected "); mpfr_print_binary (x); putchar ('\n');
                     91:       printf ("     got "); mpfr_print_binary (y); putchar ('\n');
                     92:       exit (1);
                     93:     }
                     94:
                     95:   mpfr_set_prec (x, 5);
                     96:   mpfr_set_prec (y, 5);
                     97:   mpfr_set_str_raw (x, "1.1100e-2");
                     98:   mpfr_cos (y, x, GMP_RNDD);
                     99:   mpfr_set_str_raw (x, "1.1100e-1");
                    100:   if (mpfr_cmp (y, x))
                    101:     {
                    102:       fprintf (stderr, "Error for x=1.1100e-2, rnd=GMP_RNDD\n");
                    103:       printf ("expected 1.1100e-1, got "); mpfr_print_binary (y); putchar ('\n');
                    104:       exit (1);
                    105:     }
                    106:
                    107: #ifdef HAVE_INFS
                    108:   check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
                    109:   check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
                    110:   check53 (DBL_NEG_INF, DBL_NAN, GMP_RNDN);
                    111: #endif
                    112:
                    113:   /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
                    114:   check53 (4.984987858808754279e-1, 8.783012931285841817e-1, GMP_RNDN);
                    115:   check53 (4.984987858808754279e-1, 8.783012931285840707e-1, GMP_RNDD);
                    116:   check53 (4.984987858808754279e-1, 8.783012931285840707e-1, GMP_RNDZ);
                    117:   check53 (4.984987858808754279e-1, 8.783012931285841817e-1, GMP_RNDU);
                    118:   check53 (1.00031274099908640274,  0.540039116973283217504, GMP_RNDN);
                    119:   check53 (1.00229256850978698523,  0.538371757797526551137, GMP_RNDZ);
                    120:   check53 (1.00288304857059840103,  0.537874062022526966409, GMP_RNDZ);
                    121:   check53 (1.00591265847407274059,  0.53531755997839769456,  GMP_RNDN);
                    122:
                    123:   check53 (1.00591265847407274059, 0.53531755997839769456,  GMP_RNDN);
                    124:
                    125:   test_generic (2, 100, 100);
                    126:
                    127:   mpfr_clear (x);
                    128:   mpfr_clear (y);
                    129:
                    130:   return 0;
                    131: }

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