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