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

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

1.1     ! maekawa     1: /* Test file for mpfr_set_si and mpfr_set_ui.
        !             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 <stdio.h>
        !            23: #include <stdlib.h>
        !            24: #include "gmp.h"
        !            25: #include "mpfr.h"
        !            26: #include "time.h"
        !            27:
        !            28: int
        !            29: main(int argc, char **argv)
        !            30: {
        !            31:   mpfr_t x; long k, z, d; unsigned long zl, dl, N;
        !            32:
        !            33:   mpfr_init2(x, 100);
        !            34:
        !            35:   srandom(time(NULL));
        !            36:
        !            37:   N = (argc==1) ? 1000000 : atoi(argv[1]);
        !            38:
        !            39:   for (k = 1; k <= N; k++)
        !            40:     {
        !            41:       z = random() - (1 << 30);
        !            42:       mpfr_set_si(x, z, GMP_RNDZ);
        !            43:       d = (int)mpfr_get_d(x);
        !            44:       if (d != z)
        !            45:        {
        !            46:          fprintf(stderr, "Expected %ld got %ld\n", z, d);
        !            47:          exit(1);
        !            48:        }
        !            49:     }
        !            50:
        !            51:   for (k = 1; k <= N; k++)
        !            52:     {
        !            53:       zl = random();
        !            54:       mpfr_set_ui(x, zl, GMP_RNDZ);
        !            55:       dl = (unsigned int) mpfr_get_d(x);
        !            56:       if (dl != zl)
        !            57:        {
        !            58:          fprintf(stderr, "Expected %lu got %lu\n", zl, dl);
        !            59:          exit(1);
        !            60:        }
        !            61:     }
        !            62:
        !            63:   mpfr_clear(x);
        !            64:   exit (0);
        !            65: }

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