1/* Test file for mpfr_cmp_ld. 2 3Copyright 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#include <stdio.h> 23#include <stdlib.h> 24 25#include "mpfr-test.h" 26 27int 28main (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 /* Check NAN */ 71 mpfr_clear_erangeflag (); 72 c = mpfr_cmp_ld (x, DBL_NAN); 73 if (c != 0 || !mpfr_erangeflag_p ()) 74 { 75 printf ("ERROR for NAN (1)\n"); 76#ifdef MPFR_NANISNAN 77 printf ("The reason is that NAN == NAN. Please look at the configure " 78 "output\nand Section \"In case of problem\" of the INSTALL " 79 "file.\n"); 80#endif 81 exit (1); 82 } 83 mpfr_set_nan (x); 84 mpfr_clear_erangeflag (); 85 c = mpfr_cmp_ld (x, 2.0); 86 if (c != 0 || !mpfr_erangeflag_p ()) 87 { 88 printf ("ERROR for NAN (2)\n"); 89#ifdef MPFR_NANISNAN 90 printf ("The reason is that NAN == NAN. Please look at the configure " 91 "output\nand Section \"In case of problem\" of the INSTALL " 92 "file.\n"); 93#endif 94 exit (1); 95 } 96 97 mpfr_clear(x); 98 99 tests_end_mpfr (); 100 return 0; 101} 102 103 104