xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/ttotal_order.c (revision a8c74629f602faa0ccf8a463757d7baf858bbf3a)
1 /* Test file for mpfr_total_order_p.
2 
3 Copyright 2018-2020 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramba projects, INRIA.
5 
6 This file is part of the GNU MPFR Library.
7 
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22 
23 #include "mpfr-test.h"
24 
25 static void
26 check1 (mpfr_ptr x, mpfr_ptr y)
27 {
28   if (! mpfr_total_order_p (x, x))
29     {
30       printf ("Error on mpfr_total_order_p (x, x) with\n");
31       printf ("x = ");
32       mpfr_dump (x);
33       exit (1);
34     }
35 
36   mpfr_set (y, x, MPFR_RNDN);
37 
38   if (! mpfr_total_order_p (x, y))
39     {
40       printf ("Error on mpfr_total_order_p (x, y) with\n");
41       printf ("x = ");
42       mpfr_dump (x);
43       printf ("y = ");
44       mpfr_dump (y);
45       exit (1);
46     }
47 }
48 
49 static void
50 check2 (mpfr_ptr x, mpfr_ptr y)
51 {
52   if (! mpfr_total_order_p (x, y))
53     {
54       printf ("Error on mpfr_total_order_p (x, y) with\n");
55       printf ("x = ");
56       mpfr_dump (x);
57       printf ("y = ");
58       mpfr_dump (y);
59       exit (1);
60     }
61 
62   if (mpfr_total_order_p (y, x))
63     {
64       printf ("Error on mpfr_total_order_p (y, x) with\n");
65       printf ("x = ");
66       mpfr_dump (x);
67       printf ("y = ");
68       mpfr_dump (y);
69       exit (1);
70     }
71 }
72 
73 int
74 main (void)
75 {
76   mpfr_t x[13];
77   int i, j;
78 
79   tests_start_mpfr ();
80 
81   for (i = 0; i < 13; i++)
82     mpfr_init2 (x[i], 32);
83 
84   mpfr_set_nan (x[1]);
85   MPFR_SET_NEG (x[1]);
86   mpfr_set_inf (x[2], -1);
87   mpfr_set_si (x[3], -3, MPFR_RNDN);
88   mpfr_set_si (x[4], -2, MPFR_RNDN);
89   mpfr_set_si (x[5], -1, MPFR_RNDN);
90   mpfr_set_zero (x[6], -1);
91   mpfr_set_zero (x[7], 1);
92   mpfr_set_si (x[8], 1, MPFR_RNDN);
93   mpfr_set_si (x[9], 2, MPFR_RNDN);
94   mpfr_set_si (x[10], 3, MPFR_RNDN);
95   mpfr_set_inf (x[11], 1);
96   mpfr_set_nan (x[12]);
97   MPFR_SET_POS (x[12]);
98 
99   for (i = 1; i <= 12; i++)
100     {
101       check1 (x[i], x[0]);
102       for (j = i+1; j <= 12; j++)
103         check2 (x[i], x[j]);
104     }
105 
106   for (i = 0; i < 13; i++)
107     mpfr_clear (x[i]);
108 
109   tests_end_mpfr ();
110   return 0;
111 }
112