xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tdim.c (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
1 /* Test file for mpfr_dim.
2 
3 Copyright 2004-2016 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 http://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 <stdio.h>
24 #include <stdlib.h>
25 
26 #include "mpfr-test.h"
27 
28 #define TEST_FUNCTION mpfr_dim
29 #define TWO_ARGS
30 #define TEST_RANDOM_EMIN -20
31 #define TEST_RANDOM_EMAX 20
32 #define TGENERIC_NOWARNING 1
33 #include "tgeneric.c"
34 
35 int
36 main (void)
37 {
38   mpfr_t x, y, z;
39 
40   tests_start_mpfr ();
41 
42   mpfr_init (x);
43   mpfr_init (y);
44   mpfr_init (z);
45 
46   /* case x=NaN */
47   mpfr_set_nan (x);
48   mpfr_set_ui (y, 0, MPFR_RNDN);
49   mpfr_dim (z, x, y, MPFR_RNDN);
50   if (!mpfr_nan_p (z))
51     {
52       printf ("Error in mpfr_dim (NaN, 0)\n");
53       exit (1);
54     }
55 
56   /* case x=+Inf */
57   mpfr_set_inf (x, 1);
58   mpfr_set_ui (y, 0, MPFR_RNDN);
59   mpfr_dim (z, x, y, MPFR_RNDN);
60   if (!mpfr_inf_p (z) || mpfr_sgn (z) < 0)
61     {
62       printf ("Error in mpfr_dim (+Inf, 0)\n");
63       exit (1);
64     }
65 
66   /* case x=-Inf */
67   mpfr_set_inf (x, -1);
68   mpfr_set_ui (y, 0, MPFR_RNDN);
69   mpfr_dim (z, x, y, MPFR_RNDN);
70   if (mpfr_cmp_ui (z, 0) || mpfr_sgn (z) < 0)
71     {
72       printf ("Error in mpfr_dim (-Inf, 0)\n");
73       exit (1);
74     }
75 
76   /* case x=y=+Inf */
77   mpfr_set_inf (x, 1);
78   mpfr_set_inf (y, 1);
79   mpfr_dim (z, x, y, MPFR_RNDN);
80   if (mpfr_cmp_ui (z, 0) || mpfr_sgn (z) < 0)
81     {
82       printf ("Error in mpfr_dim (+Inf, +Inf)\n");
83       exit (1);
84     }
85 
86   /* case x > y */
87   mpfr_set_ui (x, 2, MPFR_RNDN);
88   mpfr_set_ui (y, 1, MPFR_RNDN);
89   mpfr_dim (z, x, y, MPFR_RNDN);
90   if (mpfr_cmp_ui (z, 1))
91     {
92       printf ("Error in mpfr_dim (2, 1)\n");
93       exit (1);
94     }
95 
96   /* case x < y */
97   mpfr_set_ui (x, 1, MPFR_RNDN);
98   mpfr_set_ui (y, 2, MPFR_RNDN);
99   mpfr_dim (z, x, y, MPFR_RNDN);
100   if (mpfr_cmp_ui (z, 0))
101     {
102       printf ("Error in mpfr_dim (1, 2)\n");
103       exit (1);
104     }
105 
106   mpfr_clear (x);
107   mpfr_clear (y);
108   mpfr_clear (z);
109 
110   test_generic (2, 220, 42);
111 
112   tests_end_mpfr ();
113   return 0;
114 }
115