1 /* Test file for mpfr_cot. 2 3 Copyright 2005-2020 Free Software Foundation, Inc. 4 Contributed by the AriC and Caramba 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 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 #include "mpfr-test.h" 24 25 #define TEST_FUNCTION mpfr_cot 26 #define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */ 27 #include "tgeneric.c" 28 29 static void 30 check_specials (void) 31 { 32 mpfr_t x, y; 33 34 mpfr_init2 (x, 123L); 35 mpfr_init2 (y, 123L); 36 37 mpfr_set_nan (x); 38 mpfr_cot (y, x, MPFR_RNDN); 39 if (! mpfr_nan_p (y)) 40 { 41 printf ("Error: cot(NaN) != NaN\n"); 42 exit (1); 43 } 44 45 mpfr_set_inf (x, 1); 46 mpfr_cot (y, x, MPFR_RNDN); 47 if (! mpfr_nan_p (y)) 48 { 49 printf ("Error: cot(Inf) != NaN\n"); 50 exit (1); 51 } 52 53 mpfr_set_inf (x, -1); 54 mpfr_cot (y, x, MPFR_RNDN); 55 if (! mpfr_nan_p (y)) 56 { 57 printf ("Error: cot(-Inf) != NaN\n"); 58 exit (1); 59 } 60 61 /* cot(+/-0) = +/-Inf */ 62 mpfr_set_ui (x, 0, MPFR_RNDN); 63 mpfr_cot (y, x, MPFR_RNDN); 64 if (! (mpfr_inf_p (y) && mpfr_sgn (y) > 0)) 65 { 66 printf ("Error: cot(+0) != +Inf\n"); 67 exit (1); 68 } 69 mpfr_neg (x, x, MPFR_RNDN); 70 mpfr_cot (y, x, MPFR_RNDN); 71 if (! (mpfr_inf_p (y) && mpfr_sgn (y) < 0)) 72 { 73 printf ("Error: cot(-0) != -Inf\n"); 74 exit (1); 75 } 76 77 mpfr_clear (x); 78 mpfr_clear (y); 79 } 80 81 static void 82 two2emin (mpfr_exp_t e) 83 { 84 mpfr_exp_t old_emin, old_emax; 85 mpfr_t x, y; 86 int i, rnd; 87 88 old_emin = mpfr_get_emin (); 89 old_emax = mpfr_get_emax (); 90 91 if (mpfr_set_emin (-e) || mpfr_set_emax (e)) 92 { 93 printf ("Can't change exponent range\n"); 94 exit (1); 95 } 96 97 mpfr_inits2 (53, x, y, (mpfr_ptr) 0); 98 for (i = -4; i <= 4; i++) 99 RND_LOOP (rnd) 100 { 101 mpfr_set_si (y, i, MPFR_RNDN); 102 mpfr_ui_div (y, 1, y, (mpfr_rnd_t) rnd); /* no overflow/underflow */ 103 mpfr_set_si_2exp (x, i, -e, MPFR_RNDN); 104 if (ABS (i) != 3) /* not a power of 2 (not 0 either) */ 105 mpfr_sub (y, y, x, (mpfr_rnd_t) rnd); /* no overflow/underflow */ 106 mpfr_set_ui_2exp (x, 1, -e, MPFR_RNDN); 107 mpfr_div (y, y, x, (mpfr_rnd_t) rnd); /* 1/x - SIGN(x).epsilon */ 108 mpfr_set_si_2exp (x, i, -e, MPFR_RNDN); 109 mpfr_cot (x, x, (mpfr_rnd_t) rnd); 110 if (! mpfr_equal_p (x, y) && rnd != MPFR_RNDF) 111 { 112 printf ("Error in two2emin for i = %d and rnd = %s\n", 113 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 114 printf ("Got "); 115 mpfr_dump (x); 116 printf ("instead of "); 117 mpfr_dump (y); 118 exit (1); 119 } 120 } 121 mpfr_clears (x, y, (mpfr_ptr) 0); 122 123 mpfr_set_emin (old_emin); 124 mpfr_set_emax (old_emax); 125 } 126 127 int 128 main (int argc, char *argv[]) 129 { 130 tests_start_mpfr (); 131 132 check_specials (); 133 two2emin (256); 134 two2emin (MPFR_EMAX_DEFAULT); 135 if (MPFR_EMAX_MAX != MPFR_EMAX_DEFAULT) 136 two2emin (MPFR_EMAX_MAX); 137 test_generic (MPFR_PREC_MIN, 200, 5); 138 139 tests_end_mpfr (); 140 return 0; 141 } 142