Annotation of OpenXM_contrib/gmp/mpfr/tests/tset_z.c, Revision 1.1.1.2
1.1 maekawa 1: /* Test file for mpfr_set_z.
2:
1.1.1.2 ! ohara 3: Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
1.1 maekawa 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
1.1.1.2 ! ohara 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
1.1 maekawa 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
1.1.1.2 ! ohara 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! ohara 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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:
1.1.1.2 ! ohara 22: #include <stdio.h>
1.1 maekawa 23: #include <stdlib.h>
1.1.1.2 ! ohara 24: #include <time.h>
1.1 maekawa 25: #include "gmp.h"
26: #include "mpfr.h"
1.1.1.2 ! ohara 27: #include "mpfr-test.h"
1.1 maekawa 28:
1.1.1.2 ! ohara 29: void check _PROTO((long, unsigned char));
! 30: void check_large _PROTO((void));
1.1 maekawa 31:
1.1.1.2 ! ohara 32: void
! 33: check(long i, unsigned char rnd)
! 34: {
1.1 maekawa 35: mpfr_t f; mpz_t z;
36:
37: mpfr_init2(f, 53); mpz_init(z);
38: mpz_set_ui(z, i);
39: mpfr_set_z(f, z, rnd);
1.1.1.2 ! ohara 40: if ((long)mpfr_get_d1 (f) != i) {
1.1 maekawa 41: printf("Error in mpfr_set_z for i=%ld rnd_mode=%d\n",i,rnd);
42: exit(1);
43: }
44: mpfr_clear(f); mpz_clear(z);
45: }
46:
1.1.1.2 ! ohara 47: void
! 48: check_large (void)
1.1 maekawa 49: {
50: mpz_t z; mpfr_t x,y;
51:
52: mpz_init(z); mpfr_init2(x, 160); mpfr_init2(y, 160);
53: mpz_set_str(z, "77031627725494291259359895954016675357279104942148788042", 10);
54: mpfr_set_z(x, z, GMP_RNDN);
55: mpfr_set_str_raw(y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186");
56: if (mpfr_cmp(x,y)) {
57: fprintf(stderr, "Error in mpfr_set_z on large input\n"); exit(1);
58: }
59: mpz_clear(z); mpfr_clear(x); mpfr_clear(y);
60: }
61:
1.1.1.2 ! ohara 62: /* tset_z z rnd prec */
! 63:
! 64: int
! 65: main (int argc, char *argv[])
1.1 maekawa 66: {
67: long j;
68:
69: check_large();
1.1.1.2 ! ohara 70: SEED_RAND (time(NULL));
! 71: check(0, 0);
1.1 maekawa 72: for (j=0; j<1000000; j++)
1.1.1.2 ! ohara 73: check(LONG_RAND(), LONG_RAND()%4);
1.1 maekawa 74:
1.1.1.2 ! ohara 75: return 0;
! 76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>