Annotation of OpenXM_contrib/gmp/mpfr/tests/tset_q.c, Revision 1.1
1.1 ! ohara 1: /* Test file for mpfr_set_q.
! 2:
! 3: Copyright 2000, 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 <time.h>
! 25: #include "gmp.h"
! 26: #include "mpfr.h"
! 27: #include "mpfr-test.h"
! 28:
! 29: void check _PROTO((long int, long int, mp_rnd_t, double));
! 30:
! 31: void
! 32: check (long int n, long int d, mp_rnd_t rnd, double y)
! 33: {
! 34: mpq_t q;
! 35: mpfr_t x, t;
! 36: double z;
! 37: int inexact, compare;
! 38:
! 39: mpfr_init2 (x, 53);
! 40: mpfr_init2 (t, mpfr_get_prec (x) + mp_bits_per_limb);
! 41: mpq_init (q);
! 42: mpq_set_si (q, n, d);
! 43: #ifdef MPFR_HAVE_FESETROUND
! 44: mpfr_set_machine_rnd_mode (rnd);
! 45: y = (double) n / d;
! 46: #endif
! 47: inexact = mpfr_set_q (x, q, rnd);
! 48: z = mpfr_get_d1 (x);
! 49:
! 50: /* check values */
! 51: if (y != z)
! 52: {
! 53: fprintf (stderr, "Error for q=%ld/%lu and rnd=%s\n", n, d,
! 54: mpfr_print_rnd_mode (rnd));
! 55: fprintf (stderr, "libm.a gives %1.20e, mpfr_set_q gives %1.20e\n", y, z);
! 56: exit (1);
! 57: }
! 58:
! 59: /* check inexact flag */
! 60: if (mpfr_mul_ui (t, x, (d < 0) ? (-d) : d, rnd))
! 61: {
! 62: fprintf (stderr, "t <- x * d should be exact\n");
! 63: exit (1);
! 64: }
! 65: compare = mpfr_cmp_si (t, n);
! 66: if (((inexact == 0) && (compare != 0)) ||
! 67: ((inexact < 0) && (compare >= 0)) ||
! 68: ((inexact > 0) && (compare <= 0)))
! 69: {
! 70: fprintf (stderr, "wrong inexact flag: expected %d, got %d\n", compare,
! 71: inexact);
! 72: exit (1);
! 73: }
! 74:
! 75: mpfr_clear (x);
! 76: mpfr_clear (t);
! 77: mpq_clear (q);
! 78: }
! 79:
! 80: int
! 81: main (void)
! 82: {
! 83: #ifdef MPFR_HAVE_FESETROUND
! 84: long int i, n;
! 85: unsigned long int d;
! 86: double y;
! 87: unsigned char rnd;
! 88:
! 89: mpfr_test_init ();
! 90:
! 91: SEED_RAND(time(NULL));
! 92: for (i=0;i<1000000;i++) {
! 93: n = LONG_RAND();
! 94: d = LONG_RAND();
! 95: if (LONG_RAND()%2) n = -n;
! 96: rnd = LONG_RAND() % 4;
! 97: y = (double) n / d;
! 98: check(n, d, rnd, y);
! 99: }
! 100: #endif
! 101: check(-1647229822, 40619231, GMP_RNDZ, -4.055295438754120596e1);
! 102: check(-148939696, 1673285490, GMP_RNDZ, -8.9010331404953485501e-2);
! 103: check(-441322590, 273662545, GMP_RNDZ, -1.6126525096812205362);
! 104: check(-1631156895, 1677687197, GMP_RNDU, -9.722652100563177191e-1);
! 105: check(2141332571, 3117601, GMP_RNDZ, 6.8685267004982347316e2);
! 106: check(75504803, 400207282, GMP_RNDU, 1.8866424074712365155e-1);
! 107: check(643562308, 23100894, GMP_RNDD, 2.7858762002890447462e1);
! 108: check(632549085, 1831935802, GMP_RNDN, 3.4528998467600230393e-1);
! 109:
! 110: return 0;
! 111: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>