Annotation of OpenXM_contrib/gmp/mpfr/tests/tadd_ui.c, Revision 1.1
1.1 ! ohara 1: /* Test file for mpfr_add_ui
! 2:
! 3: Copyright 2000, 2001, 2002 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: /* #define DEBUG */
! 23: /* #define VERBOSE */
! 24:
! 25: #include <math.h>
! 26: #include <stdio.h>
! 27: #include <stdlib.h>
! 28: #include <time.h>
! 29: #include "gmp.h"
! 30: #include "mpfr.h"
! 31: #include "mpfr-impl.h"
! 32: #include "mpfr-test.h"
! 33:
! 34: void check3 _PROTO((double, unsigned long, unsigned int, double));
! 35: void special _PROTO((void));
! 36:
! 37: #define check(x,y,r) check3(x,y,r,0.0)
! 38:
! 39: /* checks that x+y gives the same results in double
! 40: and with mpfr with 53 bits of precision */
! 41: void
! 42: check3 (double x, unsigned long y, unsigned int rnd_mode, double z1)
! 43: {
! 44: double z2; mpfr_t xx,zz;
! 45:
! 46: mpfr_init2(xx, 53);
! 47: mpfr_init2(zz, 53);
! 48: mpfr_set_d(xx, x, rnd_mode);
! 49: mpfr_add_ui(zz, xx, y, rnd_mode);
! 50: #ifdef MPFR_HAVE_FESETROUND
! 51: mpfr_set_machine_rnd_mode(rnd_mode);
! 52: #endif
! 53: if (z1==0.0) z1 = x+y;
! 54: z2 = mpfr_get_d1 (zz);
! 55: if (z1!=z2 && !(isnan(z1) && isnan(z2))) {
! 56: printf("expected sum is %1.20e, got %1.20e\n",z1,z2);
! 57: printf("mpfr_add_ui failed for x=%1.20e y=%lu with rnd_mode=%s\n",
! 58: x, y, mpfr_print_rnd_mode(rnd_mode));
! 59: exit(1);
! 60: }
! 61: mpfr_clear(xx); mpfr_clear(zz);
! 62: }
! 63:
! 64: void
! 65: special (void)
! 66: {
! 67: mpfr_t x, y;
! 68:
! 69: mpfr_init2 (x, 63);
! 70: mpfr_init2 (y, 63);
! 71: mpfr_set_str_raw (x, "0.110100000000000001110001110010111111000000000101100011100100011");
! 72: mpfr_add_ui (y, x, 1, GMP_RNDD);
! 73: mpfr_clear (x);
! 74: mpfr_clear (y);
! 75: }
! 76:
! 77: int
! 78: main (int argc, char *argv[])
! 79: {
! 80: #ifdef MPFR_HAVE_FESETROUND
! 81: double x; unsigned long y, N; int i,rnd_mode,rnd;
! 82:
! 83: mpfr_test_init ();
! 84:
! 85: SEED_RAND (time(NULL));
! 86: N = (argc<2) ? 1000000 : atoi(argv[1]);
! 87: rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
! 88: for (i=0;i<1000000;i++) {
! 89: x = drand();
! 90: y = LONG_RAND();
! 91: if (ABS(x)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
! 92: /* avoid denormalized numbers and overflows */
! 93: rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
! 94: check(x, y, rnd);
! 95: }
! 96: }
! 97: #endif
! 98: special ();
! 99: check3 (-1.716113812768534e-140, 1271212614, GMP_RNDZ,
! 100: 1.27121261399999976e9);
! 101: check3 (1.22191250737771397120e+20, 948002822, GMP_RNDN,
! 102: 122191250738719408128.0);
! 103: check3 (-6.72658901114033715233e-165, 2000878121, GMP_RNDZ,
! 104: 2.0008781209999997615e9);
! 105: check3 (-2.0769715792901673e-5, 880524, GMP_RNDN, 8.8052399997923023e5);
! 106: #ifdef HAVE_INFS
! 107: check3 (DBL_POS_INF, 2394875, GMP_RNDN, DBL_POS_INF);
! 108: check3 (DBL_NEG_INF, 2394875, GMP_RNDN, DBL_NEG_INF);
! 109: check3 (DBL_NAN, 2394875, GMP_RNDN, DBL_NAN);
! 110: #endif
! 111:
! 112: return 0;
! 113: }
! 114:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>