1/* Test file for mpfr_cmp_d.
2
3Copyright 1999, 2001, 2002, 2003, 2004, 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
28int
29main (void)
30{
31  mpfr_t x;
32  int c;
33
34  tests_start_mpfr ();
35
36  mpfr_init2(x, IEEE_DBL_MANT_DIG);
37
38  mpfr_set_d (x, 2.34763465, MPFR_RNDN);
39  if (mpfr_cmp_d(x, 2.34763465)!=0) {
40    printf("Error in mpfr_cmp_d 2.34763465 and ");
41    mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
42    exit(1);
43  }
44  if (mpfr_cmp_d(x, 2.345)<=0) {
45    printf("Error in mpfr_cmp_d 2.345 and ");
46    mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
47    exit(1);
48  }
49  if (mpfr_cmp_d(x, 2.4)>=0) {
50    printf("Error in mpfr_cmp_d 2.4 and ");
51    mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
52    exit(1);
53  }
54
55  mpfr_set_ui (x, 0, MPFR_RNDZ);
56  mpfr_neg (x, x, MPFR_RNDZ);
57  if (mpfr_cmp_d (x, 0.0)) {
58    printf("Error in mpfr_cmp_d 0.0 and ");
59    mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
60    exit(1);
61  }
62
63  mpfr_set_ui (x, 0, MPFR_RNDN);
64  mpfr_ui_div (x, 1, x, MPFR_RNDU);
65  if (mpfr_cmp_d (x, 0.0) == 0)
66    {
67      printf ("Error in mpfr_cmp_d (Inf, 0)\n");
68      exit (1);
69    }
70
71  /* Check NAN */
72  mpfr_clear_erangeflag ();
73  c = mpfr_cmp_d (x, DBL_NAN);
74  if (c != 0 || !mpfr_erangeflag_p ())
75    {
76      printf ("ERROR for NAN (1)\n");
77#ifdef MPFR_NANISNAN
78      printf ("The reason is that NAN == NAN. Please look at the configure "
79              "output\nand Section \"In case of problem\" of the INSTALL "
80              "file.\n");
81#endif
82      exit (1);
83    }
84  mpfr_set_nan (x);
85  mpfr_clear_erangeflag ();
86  c = mpfr_cmp_d (x, 2.0);
87  if (c != 0 || !mpfr_erangeflag_p ())
88    {
89      printf ("ERROR for NAN (2)\n");
90#ifdef MPFR_NANISNAN
91      printf ("The reason is that NAN == NAN. Please look at the configure "
92              "output\nand Section \"In case of problem\" of the INSTALL "
93              "file.\n");
94#endif
95      exit (1);
96    }
97
98  mpfr_clear(x);
99
100  tests_end_mpfr ();
101  return 0;
102}
103