1 /* Test file for mpfr_coth.
3 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
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.
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.
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 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
26 #include "mpfr-test.h"
28 #define TEST_FUNCTION mpfr_coth
40 mpfr_coth (y, x, MPFR_RNDN);
43 printf ("Error: coth(NaN) != NaN\n");
48 mpfr_coth (y, x, MPFR_RNDN);
49 if (mpfr_cmp_ui (y, 1))
51 printf ("Error: coth(Inf) != 1\n");
56 mpfr_coth (y, x, MPFR_RNDN);
57 if (mpfr_cmp_si (y, -1))
59 printf ("Error: coth(-Inf) != -1\n");
63 /* coth(+/-0) = +/-Inf */
64 mpfr_set_ui (x, 0, MPFR_RNDN);
65 mpfr_coth (y, x, MPFR_RNDN);
66 if (! (mpfr_inf_p (y) && MPFR_SIGN (y) > 0))
68 printf ("Error: coth(+0) != +Inf\n");
71 mpfr_neg (x, x, MPFR_RNDN);
72 mpfr_coth (y, x, MPFR_RNDN);
73 if (! (mpfr_inf_p (y) && MPFR_SIGN (y) < 0))
75 printf ("Error: coth(-0) != -Inf\n");
91 /* bug found by Rob (Sisyphus) on 16 Sep 2005 */
92 mpfr_set_ui (x, 2, MPFR_RNDN);
94 mpfr_coth (y, x, MPFR_RNDN);
95 if (mpfr_cmp_ui (y, 1))
97 printf ("Error for coth(2), expected 1, got ");
102 mpfr_set_prec (x, 53);
103 mpfr_set_prec (y, 53);
105 mpfr_set_str (x, "18.368400284838550", 10, MPFR_RNDN);
106 mpfr_set_str (y, "1.0000000000000002", 10, MPFR_RNDN);
107 mpfr_coth (x, x, MPFR_RNDN);
108 if (mpfr_cmp (x, y) != 0)
110 printf ("Error for coth(18.368400284838550)\n");
114 mpfr_set_str (x, "18.714973875118520", 10, MPFR_RNDN);
115 mpfr_coth (x, x, MPFR_RNDN);
116 if (mpfr_cmp (x, y) != 0)
118 printf ("Error for coth(18.714973875118520)\n");
122 mpfr_set_str (x, "18.714973875118524", 10, MPFR_RNDN);
123 mpfr_coth (x, x, MPFR_RNDN);
124 if (mpfr_cmp_ui (x, 1) != 0)
126 printf ("Error for coth(18.714973875118524)\n");
135 underflowed_cothinf (void)
138 int i, inex, rnd, err = 0;
141 old_emin = mpfr_get_emin ();
146 for (i = -1; i <= 1; i += 2)
151 set_emin (2); /* 1 is not representable. */
152 inex = mpfr_coth (x, x, (mpfr_rnd_t) rnd);
154 if (! mpfr_underflow_p ())
156 printf ("Error in underflowed_cothinf (i = %d, rnd = %s):\n"
157 " The underflow flag is not set.\n",
158 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
161 mpfr_set_si (y, (i < 0 && (rnd == MPFR_RNDD || rnd == MPFR_RNDA)) ||
162 (i > 0 && (rnd == MPFR_RNDU || rnd == MPFR_RNDA))
165 mpfr_neg (y, y, MPFR_RNDN);
166 if (! (mpfr_equal_p (x, y) &&
167 MPFR_MULT_SIGN (MPFR_SIGN (x), MPFR_SIGN (y)) > 0))
169 printf ("Error in underflowed_cothinf (i = %d, rnd = %s):\n"
170 " Got ", i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
171 mpfr_print_binary (x);
172 printf (" instead of ");
173 mpfr_print_binary (y);
177 if ((rnd == MPFR_RNDD ||
178 (i > 0 && (rnd == MPFR_RNDN || rnd == MPFR_RNDZ))) && inex >= 0)
180 printf ("Error in underflowed_cothinf (i = %d, rnd = %s):\n"
181 " The inexact value must be negative.\n",
182 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
185 if ((rnd == MPFR_RNDU ||
186 (i < 0 && (rnd == MPFR_RNDN || rnd == MPFR_RNDZ))) && inex <= 0)
188 printf ("Error in underflowed_cothinf (i = %d, rnd = %s):\n"
189 " The inexact value must be positive.\n",
190 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
202 main (int argc, char *argv[])
208 test_generic (2, 200, 10);
209 underflowed_cothinf ();