1/* Test file for mpfr_dim.
2
3Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4Contributed by the Arenaire and Cacao projects, INRIA.
5
6This file is part of the GNU MPFR Library.
7
8The GNU MPFR Library is free software; you can redistribute it and/or modify
9it under the terms of the GNU Lesser General Public License as published by
10the Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
12
13The GNU MPFR Library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
2151 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
35int
36main (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