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

Annotation of OpenXM_contrib/gmp/mpfr/tests/tconst_log2.c, Revision 1.1

1.1     ! ohara       1: /* Test file for mpfr_const_log2.
        !             2:
        !             3: Copyright 1999, 2001 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 "gmp.h"
        !            25: #include "gmp-impl.h"
        !            26: #include "mpfr.h"
        !            27: #include "mpfr-impl.h"
        !            28:
        !            29: /* tlog2 [prec] [rnd] [0 = no print] */
        !            30:
        !            31: void check _PROTO ((mp_prec_t, mp_prec_t));
        !            32:
        !            33: void
        !            34: check (mp_prec_t p0, mp_prec_t p1)
        !            35: {
        !            36:   mpfr_t x, y, z;
        !            37:   mp_rnd_t rnd;
        !            38:
        !            39:   mpfr_init (x);
        !            40:   mpfr_init (y);
        !            41:   mpfr_init2 (z, p1 + 10);
        !            42:   mpfr_const_log2 (z, GMP_RNDN);
        !            43:   __mpfr_const_log2_prec = 1;
        !            44:
        !            45:   for (; p0<=p1; p0++)
        !            46:     {
        !            47:       mpfr_set_prec (x, p0);
        !            48:       mpfr_set_prec (y, p0);
        !            49:       for (rnd = 0; rnd < 4; rnd++)
        !            50:         {
        !            51:           mpfr_const_log2 (x, rnd);
        !            52:           mpfr_set (y, z, rnd);
        !            53:           if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
        !            54:                                                  rnd, p0))
        !            55:             {
        !            56:               fprintf (stderr, "mpfr_const_log2 fails for prec=%u, rnd=%s\n",
        !            57:                        (unsigned int) p0, mpfr_print_rnd_mode (rnd));
        !            58:               fprintf (stderr, "expected ");
        !            59:               mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
        !            60:               fprintf (stderr, "\ngot      ");
        !            61:               mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
        !            62:               fprintf (stderr, "\n");
        !            63:               exit (1);
        !            64:             }
        !            65:         }
        !            66:     }
        !            67:
        !            68:   mpfr_clear (x);
        !            69:   mpfr_clear (y);
        !            70:   mpfr_clear (z);
        !            71: }
        !            72:
        !            73: int
        !            74: main (int argc, char *argv[])
        !            75: {
        !            76:   mpfr_t x;
        !            77:   int p;
        !            78:   mp_rnd_t rnd;
        !            79:
        !            80:   p = (argc>1) ? atoi(argv[1]) : 53;
        !            81:   rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ;
        !            82:
        !            83:   mpfr_init (x);
        !            84:
        !            85:   check (2, 1000);
        !            86:
        !            87:   /* check precision of 2 bits */
        !            88:   mpfr_set_prec (x, 2);
        !            89:   mpfr_const_log2 (x, GMP_RNDN);
        !            90:   if (mpfr_get_d1 (x) != 0.75)
        !            91:     {
        !            92:       fprintf (stderr, "mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n");
        !            93:       fprintf (stderr, "expected 0.75, got %f\n", mpfr_get_d1 (x));
        !            94:       exit (1);
        !            95:     }
        !            96:
        !            97:   if (argc>=2)
        !            98:     {
        !            99:       mpfr_set_prec (x, p);
        !           100:       mpfr_const_log2 (x, rnd);
        !           101:       printf ("log(2)=");
        !           102:       mpfr_out_str (stdout, 10, 0, x, rnd);
        !           103:       putchar('\n');
        !           104:     }
        !           105:
        !           106:   mpfr_set_prec (x, 53);
        !           107:   mpfr_const_log2 (x, rnd);
        !           108:   if (mpfr_get_d1 (x) != 6.9314718055994530941e-1)
        !           109:     {
        !           110:       fprintf (stderr, "mpfr_const_log2 failed for prec=53\n");
        !           111:       exit (1);
        !           112:     }
        !           113:
        !           114:   mpfr_clear(x);
        !           115:
        !           116:   return 0;
        !           117: }

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