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

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

1.1       maekawa     1: /* Test file for mpfr_set_z.
                      2:
                      3: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
                      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 Library General Public License as published by
                      9: the Free Software Foundation; either version 2 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 Library General Public
                     15: License for more details.
                     16:
                     17: You should have received a copy of the GNU Library 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 <stdlib.h>
                     23: #include <unistd.h>
                     24: #include "gmp.h"
                     25: #include "mpfr.h"
                     26:
                     27: /* tset_z z rnd prec */
                     28:
                     29: void check(long i, unsigned char rnd) {
                     30:   mpfr_t f; mpz_t z;
                     31:
                     32:   mpfr_init2(f, 53); mpz_init(z);
                     33:   mpz_set_ui(z, i);
                     34:   mpfr_set_z(f, z, rnd);
                     35:   if ((long)mpfr_get_d(f) != i) {
                     36:     printf("Error in mpfr_set_z for i=%ld rnd_mode=%d\n",i,rnd);
                     37:     exit(1);
                     38:   }
                     39:   mpfr_clear(f); mpz_clear(z);
                     40: }
                     41:
                     42: void check_large()
                     43: {
                     44:   mpz_t z; mpfr_t x,y;
                     45:
                     46:   mpz_init(z); mpfr_init2(x, 160); mpfr_init2(y, 160);
                     47:   mpz_set_str(z, "77031627725494291259359895954016675357279104942148788042", 10);
                     48:   mpfr_set_z(x, z, GMP_RNDN);
                     49:   mpfr_set_str_raw(y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186");
                     50:   if (mpfr_cmp(x,y)) {
                     51:     fprintf(stderr, "Error in mpfr_set_z on large input\n"); exit(1);
                     52:   }
                     53:   mpz_clear(z); mpfr_clear(x); mpfr_clear(y);
                     54: }
                     55:
                     56: int main(argc,argv) int argc; char *argv[];
                     57: {
                     58:   long j;
                     59:
                     60:   check_large();
                     61:   srand(getpid());
                     62:   for (j=0; j<1000000; j++)
                     63:     check(lrand48(), rand()%4);
                     64:   exit (0);
                     65: }
                     66:

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