Annotation of OpenXM_contrib/gmp/mpfr/tests/tset.c, Revision 1.1
1.1 ! ohara 1: /* Test file for mpfr_set.
! 2:
! 3: Copyright 2001 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: #include <math.h>
! 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: mp_prec_t p, q;
! 33: mpfr_t x, y, z, u;
! 34: mp_rnd_t rnd;
! 35: int inexact, cmp;
! 36:
! 37: /* check prototypes of mpfr_init_set_* */
! 38: inexact = mpfr_init_set_si (x, -1, GMP_RNDN);
! 39: inexact = mpfr_init_set (y, x, GMP_RNDN);
! 40: inexact = mpfr_init_set_ui (z, 1, GMP_RNDN);
! 41: inexact = mpfr_init_set_d (u, 1.0, GMP_RNDN);
! 42:
! 43: mpfr_set_prec (y, 11);
! 44: mpfr_set_str_raw (y, "0.11111111100E-8");
! 45: mpfr_set_prec (x, 2);
! 46: mpfr_set (x, y, GMP_RNDN);
! 47: mpfr_set_str_raw (y, "1.0E-8");
! 48: if (mpfr_cmp (x, y))
! 49: {
! 50: fprintf (stderr, "Error for y=0.11111111100E-8, prec=2, rnd=GMP_RNDN\n");
! 51: exit (1);
! 52: }
! 53:
! 54: for (p=2; p<500; p++)
! 55: {
! 56: mpfr_set_prec (x, p);
! 57: mpfr_random (x);
! 58: if (LONG_RAND () % 2)
! 59: mpfr_neg (x, x, GMP_RNDN);
! 60: for (q=2; q<2*p; q++)
! 61: {
! 62: mpfr_set_prec (y, q);
! 63: for (rnd=0; rnd<4; rnd++)
! 64: {
! 65: inexact = mpfr_set (y, x, rnd);
! 66: cmp = mpfr_cmp (y, x);
! 67: if (((inexact == 0) && (cmp != 0)) ||
! 68: ((inexact > 0) && (cmp <= 0)) ||
! 69: ((inexact < 0) && (cmp >= 0)))
! 70: {
! 71: fprintf (stderr, "Wrong inexact flag in mpfr_set: expected %d, got %d\n", cmp, inexact);
! 72: exit (1);
! 73: }
! 74: }
! 75: }
! 76: }
! 77:
! 78: mpfr_clear (x);
! 79: mpfr_clear (y);
! 80: mpfr_clear (z);
! 81: mpfr_clear (u);
! 82: return 0;
! 83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>