1
/* Test file for mpfr_cmp.
3
Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
5
This file is part of the MPFR Library.
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.
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.
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. */
27
#include "mpfr-impl.h"
28
#include "mpfr-test.h"
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))
47
fprintf (stderr, "mpfr_cmp (xx, yy) returns non-zero for prec=2\n");
51
mpfr_set_prec (xx, 65);
52
mpfr_set_prec (yy, 65);
53
mpfr_set_str_raw(xx, "0.10011010101000110101010000000011001001001110001011101011111011101E623");
54
mpfr_set_str_raw(yy, "0.10011010101000110101010000000011001001001110001011101011111011100E623");
56
if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
58
printf("Error (1) in mpfr_cmp2\n");
61
mpfr_set_str_raw(xx, "0.10100010001110110111000010001000010011111101000100011101000011100");
62
mpfr_set_str_raw(yy, "0.10100010001110110111000010001000010011111101000100011101000011011");
64
if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
66
printf("Error (2) in mpfr_cmp2\n");
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");
74
if (mpfr_cmp2 (xx, yy, &p) <= 0 || p != 144)
76
printf("Error (3) in mpfr_cmp2\n");
80
mpfr_set_prec(xx, 53); mpfr_set_prec(yy, 200);
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);
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);
92
mpfr_set_prec(yy, 53);
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) {
99
"Error in mpfr_cmp(0.0, 0.1), gives %d\n", mpfr_cmp(xx, yy));
103
mpfr_set_inf (xx, 1);
104
mpfr_set_d(yy, -23489745.0329, GMP_RNDN);
105
if (mpfr_cmp(xx, yy) <= 0) {
107
"Error in mpfr_cmp(Infp, 23489745.0329), gives %d\n", mpfr_cmp(xx, yy));
111
mpfr_set_inf (xx, 1);
112
mpfr_set_inf (yy, -1);
113
if (mpfr_cmp(xx, yy) <= 0) {
115
"Error in mpfr_cmp(Infp, Infm), gives %d\n", mpfr_cmp(xx, yy));
119
mpfr_set_inf (xx, -1);
120
mpfr_set_inf (yy, 1);
121
if (mpfr_cmp(xx, yy) >= 0) {
123
"Error in mpfr_cmp(Infm, Infp), gives %d\n", mpfr_cmp(xx, yy));
127
mpfr_set_inf (xx, 1);
128
mpfr_set_inf (yy, 1);
129
if (mpfr_cmp(xx, yy) != 0) {
131
"Error in mpfr_cmp(Infp, Infp), gives %d\n", mpfr_cmp(xx, yy));
135
mpfr_set_inf (xx, -1);
136
mpfr_set_inf (yy, -1);
137
if (mpfr_cmp(xx, yy) != 0) {
139
"Error in mpfr_cmp(Infm, Infm), gives %d\n", mpfr_cmp(xx, yy));
143
mpfr_set_inf (xx, -1);
144
mpfr_set_d(yy, 2346.09234, GMP_RNDN);
145
if (mpfr_cmp(xx, yy) >= 0) {
147
"Error in mpfr_cmp(Infm, 2346.09234), gives %d\n", mpfr_cmp(xx, yy));
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);
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);
162
for (i=0;i<1000000;) { x=drand(); y=drand();
163
if (!isnan(x) && !isnan(y)) {
165
mpfr_set_d(xx, x, 0);
166
mpfr_set_d(yy, y, 0);
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",
175
mpfr_clear(xx); mpfr_clear(yy);