=================================================================== RCS file: /home/cvs/OpenXM_contrib/gmp/mpfr/tests/Attic/tcmp.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.2 diff -u -p -r1.1.1.1 -r1.1.1.2 --- OpenXM_contrib/gmp/mpfr/tests/Attic/tcmp.c 2000/09/09 14:12:19 1.1.1.1 +++ OpenXM_contrib/gmp/mpfr/tests/Attic/tcmp.c 2003/08/25 16:06:09 1.1.1.2 @@ -1,20 +1,20 @@ /* Test file for mpfr_cmp. -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria +Copyright 1999, 2001, 2002 Free Software Foundation, Inc. This file is part of the MPFR Library. The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The MPFR Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -You should have received a copy of the GNU Library General Public License +You should have received a copy of the GNU Lesser General Public License along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -23,26 +23,61 @@ MA 02111-1307, USA. */ #include #include #include "gmp.h" -#include "longlong.h" #include "mpfr.h" #include "mpfr-impl.h" +#include "mpfr-test.h" int -main() +main (void) { - double x,y; mpfr_t xx,yy; int i,c; + double x, y; + mpfr_t xx, yy; + int i, c; + mp_prec_t p; - fprintf(stderr, "Test case 'tcmp' disabled\n"); - exit(0); /* THIS TEST CASE IS NOT WORKING */ + mpfr_init (xx); + mpfr_init (yy); - mpfr_init2(xx, 65); mpfr_init2(yy, 65); + mpfr_set_prec (xx, 2); + mpfr_set_prec (yy, 2); + mpfr_set_str_raw(xx, "-0.10E0"); + mpfr_set_str_raw(yy, "-0.10E0"); + if (mpfr_cmp (xx, yy)) + { + fprintf (stderr, "mpfr_cmp (xx, yy) returns non-zero for prec=2\n"); + exit (1); + } + + mpfr_set_prec (xx, 65); + mpfr_set_prec (yy, 65); mpfr_set_str_raw(xx, "0.10011010101000110101010000000011001001001110001011101011111011101E623"); mpfr_set_str_raw(yy, "0.10011010101000110101010000000011001001001110001011101011111011100E623"); - if (mpfr_cmp2(xx,yy)!=64) { printf("Error (1) in mpfr_cmp\n"); exit(1); } + p = 0; + if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64) + { + printf("Error (1) in mpfr_cmp2\n"); + exit(1); + } mpfr_set_str_raw(xx, "0.10100010001110110111000010001000010011111101000100011101000011100"); mpfr_set_str_raw(yy, "0.10100010001110110111000010001000010011111101000100011101000011011"); - if (mpfr_cmp2(xx,yy)!=64) { printf("Error (1) in mpfr_cmp\n"); exit(1); } - mpfr_set_prec(xx,53); mpfr_set_prec(yy,200); + p = 0; + if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64) + { + printf("Error (2) in mpfr_cmp2\n"); + exit(1); + } + + mpfr_set_prec (xx, 160); mpfr_set_prec (yy, 160); + mpfr_set_str_raw (xx, "0.1E1"); + mpfr_set_str_raw (yy, "0.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000110001110100"); + p = 0; + if (mpfr_cmp2 (xx, yy, &p) <= 0 || p != 144) + { + printf("Error (3) in mpfr_cmp2\n"); + exit(1); + } + + mpfr_set_prec(xx, 53); mpfr_set_prec(yy, 200); mpfr_set_d(xx, 1.0, 0); mpfr_set_d(yy, 1.0, 0); if (mpfr_cmp(xx,yy)!=0) { @@ -55,8 +90,76 @@ main() printf("Error in mpfr_cmp: not 1.0000000002 > 1.0\n"); exit(1); } mpfr_set_prec(yy, 53); - for (i=0;i<1000000;) { - x=drand(); y=drand(); + + /* bug found by Gerardo Ballabio */ + mpfr_set_d(xx, 0.0, GMP_RNDN); + mpfr_set_d(yy, 0.1, GMP_RNDN); + if (mpfr_cmp(xx, yy) >= 0) { + fprintf(stderr, + "Error in mpfr_cmp(0.0, 0.1), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, 1); + mpfr_set_d(yy, -23489745.0329, GMP_RNDN); + if (mpfr_cmp(xx, yy) <= 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infp, 23489745.0329), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, 1); + mpfr_set_inf (yy, -1); + if (mpfr_cmp(xx, yy) <= 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infp, Infm), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, -1); + mpfr_set_inf (yy, 1); + if (mpfr_cmp(xx, yy) >= 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infm, Infp), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, 1); + mpfr_set_inf (yy, 1); + if (mpfr_cmp(xx, yy) != 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infp, Infp), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, -1); + mpfr_set_inf (yy, -1); + if (mpfr_cmp(xx, yy) != 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infm, Infm), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_inf (xx, -1); + mpfr_set_d(yy, 2346.09234, GMP_RNDN); + if (mpfr_cmp(xx, yy) >= 0) { + fprintf(stderr, + "Error in mpfr_cmp(Infm, 2346.09234), gives %d\n", mpfr_cmp(xx, yy)); + exit(1); + } + + mpfr_set_d (xx, 0.0, GMP_RNDN); + mpfr_set_d (yy, 1.0, GMP_RNDN); + if ((i = mpfr_cmp3 (xx, yy, 1)) >= 0) { + fprintf (stderr, "Error: mpfr_cmp3 (0, 1, 1) gives %d instead of a negative value\n", i); + exit (1); + } + if ((i = mpfr_cmp3 (xx, yy, -1)) <= 0) { + fprintf (stderr, "Error: mpfr_cmp3 (0, 1, -1) gives %d instead of a positive value\n", i); + exit (1); + } + + for (i=0;i<1000000;) { x=drand(); y=drand(); if (!isnan(x) && !isnan(y)) { i++; mpfr_set_d(xx, x, 0); @@ -68,6 +171,8 @@ main() } } } + mpfr_clear(xx); mpfr_clear(yy); - exit (0); + + return 0; }