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

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

1.1     ! ohara       1: /* Test file for mpfr_trunc, mpfr_floor, mpfr_ceil, mpfr_round.
        !             2:
        !             3: Copyright 2002 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 <stdio.h>
        !            23: #include <stdlib.h>
        !            24: #include "gmp.h"
        !            25: #include "mpfr.h"
        !            26: #include "mpfr-test.h"
        !            27:
        !            28: int
        !            29: main (void)
        !            30: {
        !            31:   mp_size_t s;
        !            32:   mpz_t z;
        !            33:   mp_prec_t p;
        !            34:   mpfr_t x, y, t;
        !            35:   mp_rnd_t r;
        !            36:   int inexact, sign_t;
        !            37:
        !            38:   mpfr_init (x);
        !            39:   mpfr_init (y);
        !            40:   mpz_init (z);
        !            41:   mpfr_init (t);
        !            42:   mpz_set_ui (z, 1);
        !            43:   for (s = 2; s < 100; s++)
        !            44:     {
        !            45:       /* z has exactly s bits */
        !            46:
        !            47:       mpz_mul_2exp (z, z, 1);
        !            48:       if (LONG_RAND () % 2)
        !            49:         mpz_add_ui (z, z, 1);
        !            50:       mpfr_set_prec (x, s);
        !            51:       mpfr_set_prec (t, s);
        !            52:       if (mpfr_set_z (x, z, GMP_RNDN))
        !            53:         {
        !            54:           fprintf (stderr, "Error: mpfr_set_z should be exact (s = %u)\n",
        !            55:                    (unsigned int) s);
        !            56:           exit (1);
        !            57:         }
        !            58:       for (p=2; p<100; p++)
        !            59:         {
        !            60:           mpfr_set_prec (y, p);
        !            61:           for (r=0; r<4; r++)
        !            62:             {
        !            63:               if (r == GMP_RNDN)
        !            64:                 inexact = mpfr_round (y, x);
        !            65:               else if (r == GMP_RNDZ)
        !            66:                 inexact = mpfr_trunc (y, x);
        !            67:               else if (r == GMP_RNDU)
        !            68:                 inexact = mpfr_ceil (y, x);
        !            69:               else /* r = GMP_RNDD */
        !            70:                 inexact = mpfr_floor (y, x);
        !            71:               if (mpfr_sub (t, y, x, GMP_RNDN))
        !            72:                 {
        !            73:                   fprintf (stderr, "Error: subtraction should be exact\n");
        !            74:                   exit (1);
        !            75:                 }
        !            76:               sign_t = mpfr_cmp_ui (t, 0);
        !            77:               if (((inexact == 0) && (sign_t != 0)) ||
        !            78:                   ((inexact < 0) && (sign_t >= 0)) ||
        !            79:                   ((inexact > 0) && (sign_t <= 0)))
        !            80:                 {
        !            81:                   fprintf (stderr, "Wrong inexact flag\n");
        !            82:                   exit (1);
        !            83:                 }
        !            84:             }
        !            85:         }
        !            86:     }
        !            87:   mpfr_clear (x);
        !            88:   mpfr_clear (y);
        !            89:   mpz_clear (z);
        !            90:   mpfr_clear (t);
        !            91:
        !            92:   return 0;
        !            93: }

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