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

Annotation of OpenXM_contrib/gmp/mpfr/tests/tmul_2exp.c, Revision 1.1.1.2

1.1       maekawa     1: /* Test file for mpfr_mul_2exp.
                      2:
1.1.1.2 ! ohara       3: Copyright 1999, 2001, 2002 Free Software Foundation.
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:
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24: #include <time.h>
                     25: #include "gmp.h"
                     26: #include "mpfr.h"
1.1.1.2 ! ohara      27: #include "mpfr-impl.h"
        !            28: #include "mpfr-test.h"
1.1       maekawa    29:
                     30: /* checks that x*y gives the same results in double
                     31:    and with mpfr with 53 bits of precision */
                     32:
                     33: int
1.1.1.2 ! ohara      34: main (int argc, char *argv[])
1.1       maekawa    35: {
1.1.1.2 ! ohara      36:   double x, z; mpfr_t w; unsigned long k;
1.1       maekawa    37:
                     38:   mpfr_init2(w, 53);
                     39:
1.1.1.2 ! ohara      40:   mpfr_set_inf (w, 1);
        !            41:   mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
        !            42:   if (!MPFR_IS_INF(w)) { fprintf(stderr, "Inf != Inf"); exit(-1); }
        !            43:
        !            44:   mpfr_set_nan (w);
        !            45:   mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
        !            46:   if (!MPFR_IS_NAN(w)) { fprintf(stderr, "NaN != NaN"); exit(-1); }
        !            47:
        !            48:   SEED_RAND (time(NULL));
        !            49:   for (k = 0; k < 100000; k++) {
        !            50:     x = DBL_RAND ();
        !            51:     mpfr_set_d (w, x, 0);
        !            52:     mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
        !            53:     if (x != (z = mpfr_get_d1 (w)/1024))
        !            54:       {
        !            55:        fprintf(stderr, "%f != %f\n", x, z);
        !            56:        return -1;
        !            57:       }
        !            58:
        !            59:     mpfr_set_d(w, x, 0);
        !            60:     mpfr_div_2exp(w, w, 10, GMP_RNDZ);
        !            61:     if (x != (z = mpfr_get_d1 (w)*1024))
        !            62:       {
        !            63:        fprintf(stderr, "%f != %f\n", x, z);
        !            64:        mpfr_clear(w);
        !            65:        return -1;
        !            66:       }
        !            67:   }
        !            68:
        !            69:   mpfr_clear(w);
1.1       maekawa    70:
1.1.1.2 ! ohara      71:   return 0;
        !            72: }

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