1 /* tpow -- test file for mpc_pow. 2 3 Copyright (C) 2009, 2011, 2012, 2013 INRIA 4 5 This file is part of GNU MPC. 6 7 GNU MPC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU Lesser General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 15 more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with this program. If not, see http://www.gnu.org/licenses/ . 19 */ 20 21 #include "mpc-tests.h" 22 23 static void 24 reuse_bug (void) 25 { 26 /* bug found by the automatic builds on 27 http://hydra.nixos.org/build/1469029/log/raw */ 28 mpc_t x, y, z; 29 mp_prec_t prec = 2; 30 31 for (prec = 2; prec <= 20; prec ++) 32 { 33 mpc_init2 (x, prec); 34 mpc_init2 (y, prec); 35 mpc_init2 (z, prec); 36 37 mpfr_set_ui (mpc_realref (x), 0ul, MPFR_RNDN); 38 mpfr_set_ui_2exp (mpc_imagref (x), 3ul, -2, MPFR_RNDN); 39 mpc_set_ui (y, 8ul, MPC_RNDNN); 40 41 mpc_pow (z, x, y, MPC_RNDNN); 42 mpc_pow (y, x, y, MPC_RNDNN); 43 if (mpfr_signbit (mpc_imagref (y)) != mpfr_signbit (mpc_imagref (z))) 44 { 45 printf ("Error: regression, reuse_bug reproduced\n"); 46 exit (1); 47 } 48 49 mpc_clear (x); 50 mpc_clear (y); 51 mpc_clear (z); 52 } 53 } 54 55 /* at precision 53, mpc_pow gave (inf,-inf), and 56 at precision 73, it gave (inf,inf) */ 57 static void 58 bug20200208 (void) 59 { 60 mpc_t x, y, z, zr; 61 mpfr_prec_t prec1 = 53, prec2 = 73; 62 63 mpc_init2 (x, prec1); 64 mpc_init2 (y, prec1); 65 mpc_init2 (z, prec1); 66 mpc_init2 (zr, prec2); 67 mpfr_set_d (mpc_realref (x), 2.0851332234623992e-197, MPFR_RNDN); 68 mpfr_set_d (mpc_imagref (x), -5.6221457829327427e-17, MPFR_RNDN); 69 mpfr_set_d (mpc_realref (y), -2.1866902464899554e+138, MPFR_RNDN); 70 mpfr_set_d (mpc_imagref (y), 2.5932544562430328e-234, MPFR_RNDN); 71 mpc_pow (z, x, y, MPC_RNDNN); 72 mpc_pow (zr, x, y, MPC_RNDNN); 73 if (mpc_cmp (z, zr)) 74 { 75 printf ("Inconsistent power with different precisions:\n"); 76 mpfr_printf ("prec %lu: (%Re,%Re)\n", 77 prec1, mpc_realref (z), mpc_imagref (z)); 78 mpfr_printf ("prec %lu: (%Re,%Re)\n", 79 prec2, mpc_realref (zr), mpc_imagref (zr)); 80 exit (1); 81 } 82 mpc_clear (x); 83 mpc_clear (y); 84 mpc_clear (z); 85 mpc_clear (zr); 86 } 87 88 #define MPC_FUNCTION_CALL \ 89 P[0].mpc_inex = mpc_pow (P[1].mpc, P[2].mpc, P[3].mpc, P[4].mpc_rnd) 90 #define MPC_FUNCTION_CALL_REUSE_OP1 \ 91 P[0].mpc_inex = mpc_pow (P[1].mpc, P[1].mpc, P[3].mpc, P[4].mpc_rnd) 92 #define MPC_FUNCTION_CALL_REUSE_OP2 \ 93 P[0].mpc_inex = mpc_pow (P[1].mpc, P[2].mpc, P[1].mpc, P[4].mpc_rnd) 94 95 #include "data_check.tpl" 96 #include "tgeneric.tpl" 97 98 int 99 main (void) 100 { 101 test_start (); 102 103 bug20200208 (); 104 105 reuse_bug (); 106 107 data_check_template ("pow.dsc", "pow.dat"); 108 109 tgeneric_template ("pow.dsc", 2, 1024, 7, 10); 110 111 test_end (); 112 113 return 0; 114 } 115