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

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

1.1     ! maekawa     1: /* Test file for mpfr_cmp2.
        !             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 <math.h>
        !            25: #include "gmp.h"
        !            26: #include "longlong.h"
        !            27: #include "mpfr.h"
        !            28: #include "mpfr-impl.h"
        !            29: #ifdef IRIX64
        !            30: #include <sys/fpu.h>
        !            31: #endif
        !            32:
        !            33: extern int isnan();
        !            34:
        !            35: void tcmp2(x, y, i) double x, y; int i;
        !            36: {
        !            37:   mpfr_t xx,yy; int j;
        !            38:
        !            39:   if (i==-1) {
        !            40:     if (x==y) i=53;
        !            41:     else i = (int) floor(log(x)/log(2.0)) - (int) floor(log(x-y)/log(2.0));
        !            42:   }
        !            43:   mpfr_init2(xx, 53); mpfr_init2(yy, 53);
        !            44:   mpfr_set_d(xx, x, 0);
        !            45:   mpfr_set_d(yy, y, 0);
        !            46:   if ((j=mpfr_cmp2(xx, yy)) != i) {
        !            47:     printf("Error in mpfr_cmp2: x=%1.20e y=%1.20e mpfr_cmp2(x,y)=%d instead of %d\n",x,y,j,i);
        !            48:     exit(1);
        !            49:   }
        !            50:   mpfr_set_prec(xx, 127); mpfr_set_prec(yy, 127);
        !            51:   mpfr_set_str_raw(xx, "0.1011010000110111111000000101011110110001000101101011011110010010011110010000101101000010011001100110010000000010110000101000101E6");
        !            52:   mpfr_set_str_raw(yy, "0.1011010000110111111000000101011011111100011101000011001111000010100010100110110100110010011001100110010000110010010110000010110E6");
        !            53:   if ((j=mpfr_cmp2(xx, yy)) != 32) {
        !            54:     printf("Error in mpfr_cmp2:\n");
        !            55:     printf("x="); mpfr_print_raw(xx); putchar('\n');
        !            56:     printf("y="); mpfr_print_raw(yy); putchar('\n');
        !            57:     printf("got %d, expected 32\n", j);
        !            58:     exit(1);
        !            59:   }
        !            60:   mpfr_clear(xx); mpfr_clear(yy);
        !            61: }
        !            62:
        !            63: int main()
        !            64: {
        !            65:   int i,j; double x=1.0, y, z;
        !            66: #ifdef IRIX64
        !            67:     /* to get denormalized numbers on IRIX64 */
        !            68:     union fpc_csr exp;
        !            69:     exp.fc_word = get_fpc_csr();
        !            70:     exp.fc_struct.flush = 0;
        !            71:     set_fpc_csr(exp.fc_word);
        !            72: #endif
        !            73:
        !            74:   tcmp2(1.06022698059744327881e+71, 1.05824655795525779205e+71, -1);
        !            75:   tcmp2(1.0, 1.0, 53);
        !            76:   for (i=0;i<54;i++) {
        !            77:     tcmp2(1.0, 1.0-x, i);
        !            78:     x /= 2.0;
        !            79:   }
        !            80:   for (j=0;j<1000000;j++) {
        !            81:     x = drand48();
        !            82:     y = drand48();
        !            83:     if (x<y) { z=x; x=y; y=z; }
        !            84:     if (y != 0.0 && y != -0.0) tcmp2(x, y, -1);
        !            85:   }
        !            86:   exit (0);
        !            87: }
        !            88:

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