1/* tnorm -- test file for mpc_norm. 2 3Copyright (C) 2008, 2011 INRIA 4 5This file is part of GNU MPC. 6 7GNU MPC is free software; you can redistribute it and/or modify it under 8the terms of the GNU Lesser General Public License as published by the 9Free Software Foundation; either version 3 of the License, or (at your 10option) any later version. 11 12GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 15more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with this program. If not, see http://www.gnu.org/licenses/ . 19*/ 20 21#include "mpc-tests.h" 22 23static void 24test_underflow (void) 25{ 26 mpfr_exp_t emin = mpfr_get_emin (); 27 mpc_t z; 28 mpfr_t f; 29 int inex; 30 31 mpfr_set_emin (-1); /* smallest positive number is 0.5*2^emin = 0.25 */ 32 mpc_init2 (z, 10); 33 mpfr_set_ui_2exp (mpc_realref (z), 1023, -11, GMP_RNDN); /* exact */ 34 mpfr_set_ui_2exp (mpc_imagref (z), 1023, -11, GMP_RNDN); /* exact */ 35 mpfr_init2 (f, 10); 36 37 inex = mpc_norm (f, z, GMP_RNDZ); /* should give 511/1024 */ 38 if (inex >= 0) 39 { 40 printf ("Error in underflow case (1)\n"); 41 printf ("expected inex < 0, got %d\n", inex); 42 exit (1); 43 } 44 if (mpfr_cmp_ui_2exp (f, 511, -10) != 0) 45 { 46 printf ("Error in underflow case (1)\n"); 47 printf ("got "); 48 mpfr_dump (f); 49 printf ("expected "); 50 mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ); 51 mpfr_dump (f); 52 exit (1); 53 } 54 55 inex = mpc_norm (f, z, GMP_RNDN); /* should give 511/1024 */ 56 if (inex >= 0) 57 { 58 printf ("Error in underflow case (2)\n"); 59 printf ("expected inex < 0, got %d\n", inex); 60 exit (1); 61 } 62 if (mpfr_cmp_ui_2exp (f, 511, -10) != 0) 63 { 64 printf ("Error in underflow case (2)\n"); 65 printf ("got "); 66 mpfr_dump (f); 67 printf ("expected "); 68 mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ); 69 mpfr_dump (f); 70 exit (1); 71 } 72 73 inex = mpc_norm (f, z, GMP_RNDU); /* should give 1023/2048 */ 74 if (inex <= 0) 75 { 76 printf ("Error in underflow case (3)\n"); 77 printf ("expected inex > 0, got %d\n", inex); 78 exit (1); 79 } 80 if (mpfr_cmp_ui_2exp (f, 1023, -11) != 0) 81 { 82 printf ("Error in underflow case (3)\n"); 83 printf ("got "); 84 mpfr_dump (f); 85 printf ("expected "); 86 mpfr_set_ui_2exp (f, 1023, -11, GMP_RNDZ); 87 mpfr_dump (f); 88 exit (1); 89 } 90 91 mpc_clear (z); 92 mpfr_clear (f); 93 mpfr_set_emin (emin); 94} 95 96int 97main (void) 98{ 99 DECL_FUNC (FC, f, mpc_norm); 100 101 test_start (); 102 103 data_check (f, "norm.dat"); 104 tgeneric (f, 2, 1024, 1, 4096); 105 test_underflow (); 106 107 test_end (); 108 109 return 0; 110} 111