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

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

1.1     ! ohara       1: /* Test file for mpfr_trunc, mpfr_ceil, mpfr_floor.
        !             2:
        !             3: Copyright 1999, 2000, 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 "mpfr.h"
        !            26: #include "mpfr-impl.h"
        !            27:
        !            28: #define SIZEX 100
        !            29:
        !            30: int
        !            31: main (void)
        !            32: {
        !            33:   int j, k; mpfr_t x, y, z, t, y2, z2, t2;
        !            34:
        !            35:   mpfr_init2(x, SIZEX);
        !            36:   mpfr_init2(y, SIZEX);
        !            37:   mpfr_init2(z, SIZEX);
        !            38:   mpfr_init2(t, SIZEX);
        !            39:   mpfr_init2(y2, SIZEX);
        !            40:   mpfr_init2(z2, SIZEX);
        !            41:   mpfr_init2(t2, SIZEX);
        !            42:
        !            43:   mpfr_set_d(x, 0.5, GMP_RNDN);
        !            44:   mpfr_ceil(y, x);
        !            45:   if (mpfr_get_d1 (y) != 1.0) {
        !            46:     fprintf(stderr, "Error in mpfr_ceil for x=0.5: expected 1.0, got %f\n",
        !            47:            mpfr_get_d1 (y)); exit(1);
        !            48:   }
        !            49:
        !            50:   mpfr_set_d(x, 0.0, GMP_RNDN);
        !            51:   mpfr_ceil(y, x);
        !            52:   if (mpfr_get_d1 (y) != 0.0) {
        !            53:     fprintf(stderr, "Error in mpfr_ceil for x=0.0: expected 0.0, got %f\n",
        !            54:            mpfr_get_d1 (y)); exit(1);
        !            55:   }
        !            56:
        !            57:   mpfr_set_d(x, 1.0, GMP_RNDN);
        !            58:   mpfr_ceil(y, x);
        !            59:   if (mpfr_get_d1 (y) != 1.0) {
        !            60:     fprintf(stderr, "Error in mpfr_ceil for x=1.0: expected 1.0, got %f\n",
        !            61:            mpfr_get_d1 (y)); exit(1);
        !            62:   }
        !            63:
        !            64:   for (j=0;j<1000;j++) {
        !            65:
        !            66:     mpfr_random(x);
        !            67:     MPFR_EXP(x) = 2;
        !            68:
        !            69:     for (k = 2; k <= SIZEX; k++)
        !            70:       {
        !            71:        mpfr_set_prec(y, k);
        !            72:        mpfr_set_prec(y2, k);
        !            73:        mpfr_set_prec(z, k);
        !            74:        mpfr_set_prec(z2, k);
        !            75:        mpfr_set_prec(t, k);
        !            76:        mpfr_set_prec(t2, k);
        !            77:
        !            78:        mpfr_floor(y, x);
        !            79:        mpfr_set(y2, x, GMP_RNDD);
        !            80:
        !            81:        mpfr_trunc(z, x);
        !            82:        mpfr_set(z2, x, GMP_RNDZ);
        !            83:
        !            84:        mpfr_ceil(t, x);
        !            85:        mpfr_set(t2, x, GMP_RNDU);
        !            86:
        !            87:        if (!mpfr_eq(y, y2, k))
        !            88:          {
        !            89:            printf("Error in floor, x = "); mpfr_print_binary(x); printf("\n");
        !            90:            printf("floor(x) = "); mpfr_print_binary(y); printf("\n");
        !            91:            printf("round(x, RNDD) = "); mpfr_print_binary(y2); printf("\n");
        !            92:            mpfr_clear(x);
        !            93:            mpfr_clear(y);
        !            94:            mpfr_clear(y2);
        !            95:            mpfr_clear(z);
        !            96:            mpfr_clear(z2);
        !            97:            mpfr_clear(t);
        !            98:            mpfr_clear(t2);
        !            99:            exit(-1);
        !           100:          }
        !           101:
        !           102:        if (!mpfr_eq(z, z2, k))
        !           103:          {
        !           104:            printf("Error in trunc, x = "); mpfr_print_binary(x); printf("\n");
        !           105:            printf("trunc(x) = "); mpfr_print_binary(z); printf("\n");
        !           106:            printf("round(x, RNDZ) = "); mpfr_print_binary(z2); printf("\n");
        !           107:            mpfr_clear(x);
        !           108:            mpfr_clear(y);
        !           109:            mpfr_clear(y2);
        !           110:            mpfr_clear(z);
        !           111:            mpfr_clear(z2);
        !           112:            mpfr_clear(t);
        !           113:            mpfr_clear(t2);
        !           114:            exit(-1);
        !           115:          }
        !           116:
        !           117:        if (!mpfr_eq(y, y2, k))
        !           118:          {
        !           119:            printf("Error in ceil, x = "); mpfr_print_binary(x); printf("\n");
        !           120:            printf("ceil(x) = "); mpfr_print_binary(t); printf("\n");
        !           121:            printf("round(x, RNDU) = "); mpfr_print_binary(t2); printf("\n");
        !           122:            mpfr_clear(x);
        !           123:            mpfr_clear(y);
        !           124:            mpfr_clear(y2);
        !           125:            mpfr_clear(z);
        !           126:            mpfr_clear(z2);
        !           127:            mpfr_clear(t);
        !           128:            mpfr_clear(t2);
        !           129:            exit(-1);
        !           130:          }
        !           131:        MPFR_EXP(x)++;
        !           132:       }
        !           133:   }
        !           134:
        !           135:   mpfr_clear(x);
        !           136:   mpfr_clear(y);
        !           137:   mpfr_clear(y2);
        !           138:   mpfr_clear(z);
        !           139:   mpfr_clear(z2);
        !           140:   mpfr_clear(t);
        !           141:   mpfr_clear(t2);
        !           142:
        !           143:   return 0;
        !           144: }

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