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

Annotation of OpenXM_contrib/gmp/mpfr/tests/tcmp.c, Revision 1.1.1.2

1.1       maekawa     1: /* Test file for mpfr_cmp.
                      2:
1.1.1.2 ! ohara       3: Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
1.1       maekawa     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
1.1.1.2 ! ohara       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
1.1       maekawa    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
1.1.1.2 ! ohara      14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    15: License for more details.
                     16:
1.1.1.2 ! ohara      17: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    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 "mpfr.h"
                     27: #include "mpfr-impl.h"
1.1.1.2 ! ohara      28: #include "mpfr-test.h"
1.1       maekawa    29:
                     30: int
1.1.1.2 ! ohara      31: main (void)
1.1       maekawa    32: {
1.1.1.2 ! ohara      33:   double x, y;
        !            34:   mpfr_t xx, yy;
        !            35:   int i, c;
        !            36:   mp_prec_t p;
        !            37:
        !            38:   mpfr_init (xx);
        !            39:   mpfr_init (yy);
        !            40:
        !            41:   mpfr_set_prec (xx, 2);
        !            42:   mpfr_set_prec (yy, 2);
        !            43:   mpfr_set_str_raw(xx, "-0.10E0");
        !            44:   mpfr_set_str_raw(yy, "-0.10E0");
        !            45:   if (mpfr_cmp (xx, yy))
        !            46:     {
        !            47:       fprintf (stderr, "mpfr_cmp (xx, yy) returns non-zero for prec=2\n");
        !            48:       exit (1);
        !            49:     }
1.1       maekawa    50:
1.1.1.2 ! ohara      51:   mpfr_set_prec (xx, 65);
        !            52:   mpfr_set_prec (yy, 65);
1.1       maekawa    53:   mpfr_set_str_raw(xx, "0.10011010101000110101010000000011001001001110001011101011111011101E623");
                     54:   mpfr_set_str_raw(yy, "0.10011010101000110101010000000011001001001110001011101011111011100E623");
1.1.1.2 ! ohara      55:   p = 0;
        !            56:   if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
        !            57:     {
        !            58:       printf("Error (1) in mpfr_cmp2\n");
        !            59:       exit(1);
        !            60:     }
1.1       maekawa    61:   mpfr_set_str_raw(xx, "0.10100010001110110111000010001000010011111101000100011101000011100");
                     62:   mpfr_set_str_raw(yy, "0.10100010001110110111000010001000010011111101000100011101000011011");
1.1.1.2 ! ohara      63:   p = 0;
        !            64:   if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
        !            65:     {
        !            66:       printf("Error (2) in mpfr_cmp2\n");
        !            67:       exit(1);
        !            68:     }
        !            69:
        !            70:   mpfr_set_prec (xx, 160); mpfr_set_prec (yy, 160);
        !            71:   mpfr_set_str_raw (xx, "0.1E1");
        !            72:   mpfr_set_str_raw (yy, "0.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000110001110100");
        !            73:   p = 0;
        !            74:   if (mpfr_cmp2 (xx, yy, &p) <= 0 || p != 144)
        !            75:     {
        !            76:       printf("Error (3) in mpfr_cmp2\n");
        !            77:       exit(1);
        !            78:     }
        !            79:
        !            80:   mpfr_set_prec(xx, 53); mpfr_set_prec(yy, 200);
1.1       maekawa    81:   mpfr_set_d(xx, 1.0, 0);
                     82:   mpfr_set_d(yy, 1.0, 0);
                     83:   if (mpfr_cmp(xx,yy)!=0) {
                     84:     printf("Error in mpfr_cmp: 1.0 != 1.0\n"); exit(1);
                     85:   }
                     86:   mpfr_set_prec(yy, 31);
                     87:   mpfr_set_d(xx, 1.0000000002, 0);
                     88:   mpfr_set_d(yy, 1.0, 0);
                     89:   if (!(mpfr_cmp(xx,yy)>0)) {
                     90:     printf("Error in mpfr_cmp: not 1.0000000002 > 1.0\n"); exit(1);
                     91:   }
                     92:   mpfr_set_prec(yy, 53);
1.1.1.2 ! ohara      93:
        !            94:   /* bug found by Gerardo Ballabio */
        !            95:   mpfr_set_d(xx, 0.0, GMP_RNDN);
        !            96:   mpfr_set_d(yy, 0.1, GMP_RNDN);
        !            97:   if (mpfr_cmp(xx, yy) >= 0) {
        !            98:     fprintf(stderr,
        !            99:            "Error in mpfr_cmp(0.0, 0.1), gives %d\n", mpfr_cmp(xx, yy));
        !           100:     exit(1);
        !           101:   }
        !           102:
        !           103:   mpfr_set_inf (xx, 1);
        !           104:   mpfr_set_d(yy, -23489745.0329, GMP_RNDN);
        !           105:   if (mpfr_cmp(xx, yy) <= 0) {
        !           106:     fprintf(stderr,
        !           107:            "Error in mpfr_cmp(Infp, 23489745.0329), gives %d\n", mpfr_cmp(xx, yy));
        !           108:     exit(1);
        !           109:   }
        !           110:
        !           111:   mpfr_set_inf (xx, 1);
        !           112:   mpfr_set_inf (yy, -1);
        !           113:   if (mpfr_cmp(xx, yy) <= 0) {
        !           114:     fprintf(stderr,
        !           115:            "Error in mpfr_cmp(Infp, Infm), gives %d\n", mpfr_cmp(xx, yy));
        !           116:     exit(1);
        !           117:   }
        !           118:
        !           119:   mpfr_set_inf (xx, -1);
        !           120:   mpfr_set_inf (yy, 1);
        !           121:   if (mpfr_cmp(xx, yy) >= 0) {
        !           122:     fprintf(stderr,
        !           123:            "Error in mpfr_cmp(Infm, Infp), gives %d\n", mpfr_cmp(xx, yy));
        !           124:     exit(1);
        !           125:   }
        !           126:
        !           127:   mpfr_set_inf (xx, 1);
        !           128:   mpfr_set_inf (yy, 1);
        !           129:   if (mpfr_cmp(xx, yy) != 0) {
        !           130:     fprintf(stderr,
        !           131:            "Error in mpfr_cmp(Infp, Infp), gives %d\n", mpfr_cmp(xx, yy));
        !           132:     exit(1);
        !           133:   }
        !           134:
        !           135:   mpfr_set_inf (xx, -1);
        !           136:   mpfr_set_inf (yy, -1);
        !           137:   if (mpfr_cmp(xx, yy) != 0) {
        !           138:     fprintf(stderr,
        !           139:            "Error in mpfr_cmp(Infm, Infm), gives %d\n", mpfr_cmp(xx, yy));
        !           140:     exit(1);
        !           141:   }
        !           142:
        !           143:   mpfr_set_inf (xx, -1);
        !           144:   mpfr_set_d(yy, 2346.09234, GMP_RNDN);
        !           145:   if (mpfr_cmp(xx, yy) >= 0) {
        !           146:     fprintf(stderr,
        !           147:            "Error in mpfr_cmp(Infm, 2346.09234), gives %d\n", mpfr_cmp(xx, yy));
        !           148:     exit(1);
        !           149:   }
        !           150:
        !           151:   mpfr_set_d (xx, 0.0, GMP_RNDN);
        !           152:   mpfr_set_d (yy, 1.0, GMP_RNDN);
        !           153:   if ((i = mpfr_cmp3 (xx, yy, 1)) >= 0) {
        !           154:     fprintf (stderr, "Error: mpfr_cmp3 (0, 1, 1) gives %d instead of a negative value\n", i);
        !           155:     exit (1);
        !           156:   }
        !           157:   if ((i = mpfr_cmp3 (xx, yy, -1)) <= 0) {
        !           158:     fprintf (stderr, "Error: mpfr_cmp3 (0, 1, -1) gives %d instead of a positive value\n", i);
        !           159:     exit (1);
        !           160:   }
        !           161:
        !           162:   for (i=0;i<1000000;) {    x=drand(); y=drand();
1.1       maekawa   163:     if (!isnan(x) && !isnan(y)) {
                    164:       i++;
                    165:       mpfr_set_d(xx, x, 0);
                    166:       mpfr_set_d(yy, y, 0);
                    167:       c = mpfr_cmp(xx,yy);
                    168:       if ((c>0 && x<=y) || (c==0 && x!=y) || (c<0 && x>=y)) {
                    169:        printf("Error in mpfr_cmp with x=%1.20e, y=%1.20e mpfr_cmp(x,y)=%d\n",
                    170:               x,y,c); exit(1);
                    171:       }
                    172:     }
                    173:   }
1.1.1.2 ! ohara     174:
1.1       maekawa   175:   mpfr_clear(xx); mpfr_clear(yy);
1.1.1.2 ! ohara     176:
        !           177:   return 0;
1.1       maekawa   178: }

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