int main (void) { mpfr_t x; int c; tests_start_mpfr (); mpfr_init2(x, MPFR_LDBL_MANT_DIG); mpfr_set_ld (x, 2.34763465, GMP_RNDN); if (mpfr_cmp_ld(x, 2.34763465)!=0) { printf("Error in mpfr_cmp_ld 2.34763465 and "); mpfr_out_str(stdout, 10, 0, x, GMP_RNDN); putchar('\n'); exit(1); } if (mpfr_cmp_ld(x, 2.345)<=0) { printf("Error in mpfr_cmp_ld 2.345 and "); mpfr_out_str(stdout, 10, 0, x, GMP_RNDN); putchar('\n'); exit(1); } if (mpfr_cmp_ld(x, 2.4)>=0) { printf("Error in mpfr_cmp_ld 2.4 and "); mpfr_out_str(stdout, 10, 0, x, GMP_RNDN); putchar('\n'); exit(1); } mpfr_set_ui (x, 0, GMP_RNDZ); mpfr_neg (x, x, GMP_RNDZ); if (mpfr_cmp_ld (x, 0.0)) { printf("Error in mpfr_cmp_ld 0.0 and "); mpfr_out_str(stdout, 10, 0, x, GMP_RNDN); putchar('\n'); exit(1); } mpfr_set_ui (x, 0, GMP_RNDN); mpfr_ui_div (x, 1, x, GMP_RNDU); if (mpfr_cmp_ld (x, 0.0) == 0) { printf ("Error in mpfr_cmp_ld (Inf, 0)\n"); exit (1); } /* Check NAN */ mpfr_clear_erangeflag (); c = mpfr_cmp_ld (x, DBL_NAN); if (c != 0 || !mpfr_erangeflag_p ()) { printf ("ERROR for NAN (1)\n"); exit (1); } mpfr_set_nan (x); mpfr_clear_erangeflag (); c = mpfr_cmp_ld (x, 2.0); if (c != 0 || !mpfr_erangeflag_p ()) { printf ("ERROR for NAN (2)\n"); exit (1); } mpfr_clear(x); tests_end_mpfr (); return 0; }
int main (void) { mpfr_t x; tests_start_mpfr (); mpfr_init2(x, MPFR_LDBL_MANT_DIG); mpfr_set_ld (x, 2.34763465L, MPFR_RNDN); if (mpfr_cmp_ld(x, 2.34763465L)!=0) { printf("Error in mpfr_cmp_ld 2.34763465 and "); mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n'); exit(1); } if (mpfr_cmp_ld(x, 2.345L)<=0) { printf("Error in mpfr_cmp_ld 2.345 and "); mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n'); exit(1); } if (mpfr_cmp_ld(x, 2.4L)>=0) { printf("Error in mpfr_cmp_ld 2.4 and "); mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n'); exit(1); } mpfr_set_ui (x, 0, MPFR_RNDZ); mpfr_neg (x, x, MPFR_RNDZ); if (mpfr_cmp_ld (x, 0.0)) { printf("Error in mpfr_cmp_ld 0.0 and "); mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN); putchar('\n'); exit(1); } mpfr_set_ui (x, 0, MPFR_RNDN); mpfr_ui_div (x, 1, x, MPFR_RNDU); if (mpfr_cmp_ld (x, 0.0) == 0) { printf ("Error in mpfr_cmp_ld (Inf, 0)\n"); exit (1); } #if !defined(MPFR_ERRDIVZERO) /* Check NAN */ { int c; mpfr_clear_erangeflag (); c = mpfr_cmp_ld (x, DBL_NAN); if (c != 0 || !mpfr_erangeflag_p ()) { printf ("ERROR for NAN (1)\n"); #ifdef MPFR_NANISNAN printf ("The reason is that NAN == NAN. Please look at the configure " "output\nand Section \"In case of problem\" of the INSTALL " "file.\n"); #endif exit (1); } mpfr_set_nan (x); mpfr_clear_erangeflag (); c = mpfr_cmp_ld (x, 2.0); if (c != 0 || !mpfr_erangeflag_p ()) { printf ("ERROR for NAN (2)\n"); #ifdef MPFR_NANISNAN printf ("The reason is that NAN == NAN. Please look at the configure " "output\nand Section \"In case of problem\" of the INSTALL " "file.\n"); #endif exit (1); } } #endif /* MPFR_ERRDIVZERO */ mpfr_clear(x); tests_end_mpfr (); return 0; }