Imported Upstream version 3.1.1
[platform/upstream/mpfr.git] / tests / tcmp_ld.c
1 /* Test file for mpfr_cmp_ld.
2
3 Copyright 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel 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 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "mpfr-test.h"
26
27 int
28 main (void)
29 {
30   mpfr_t x;
31   int c;
32
33   tests_start_mpfr ();
34
35   mpfr_init2(x, MPFR_LDBL_MANT_DIG);
36
37   mpfr_set_ld (x, 2.34763465L, MPFR_RNDN);
38   if (mpfr_cmp_ld(x, 2.34763465L)!=0) {
39     printf("Error in mpfr_cmp_ld 2.34763465 and ");
40     mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
41     exit(1);
42   }
43   if (mpfr_cmp_ld(x, 2.345L)<=0) {
44     printf("Error in mpfr_cmp_ld 2.345 and ");
45     mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
46     exit(1);
47   }
48   if (mpfr_cmp_ld(x, 2.4L)>=0) {
49     printf("Error in mpfr_cmp_ld 2.4 and ");
50     mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
51     exit(1);
52   }
53
54   mpfr_set_ui (x, 0, MPFR_RNDZ);
55   mpfr_neg (x, x, MPFR_RNDZ);
56   if (mpfr_cmp_ld (x, 0.0)) {
57     printf("Error in mpfr_cmp_ld 0.0 and ");
58     mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n');
59     exit(1);
60   }
61
62   mpfr_set_ui (x, 0, MPFR_RNDN);
63   mpfr_ui_div (x, 1, x, MPFR_RNDU);
64   if (mpfr_cmp_ld (x, 0.0) == 0)
65     {
66       printf ("Error in mpfr_cmp_ld (Inf, 0)\n");
67       exit (1);
68     }
69
70 #if !defined(MPFR_ERRDIVZERO)
71   /* Check NAN */
72   mpfr_clear_erangeflag ();
73   c = mpfr_cmp_ld (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_ld (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 #endif  /* MPFR_ERRDIVZERO */
98
99   mpfr_clear(x);
100
101   tests_end_mpfr ();
102   return 0;
103 }
104
105