1 /* Test file for mpfr_tanh.
3 Copyright 2001, 2002, 2003, 2004, 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_tanh
29 #define TEST_RANDOM_EMIN -36
30 #define TEST_RANDOM_EMAX 36
41 mpfr_tanh (x, x, MPFR_RNDN);
42 MPFR_ASSERTN(mpfr_nan_p (x));
45 mpfr_tanh (x, x, MPFR_RNDN);
46 MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0);
49 mpfr_tanh (x, x, MPFR_RNDN);
50 MPFR_ASSERTN(mpfr_cmp_si (x, -1) == 0);
52 mpfr_set_prec (x, 10);
53 mpfr_set_str_binary (x, "-0.1001011001");
54 mpfr_tanh (x, x, MPFR_RNDN);
55 MPFR_ASSERTN(mpfr_cmp_si_2exp (x, -135, -8) == 0);
61 special_overflow (void)
65 mpfr_exp_t emin, emax;
67 emin = mpfr_get_emin ();
68 emax = mpfr_get_emax ();
70 mpfr_clear_overflow ();
76 mpfr_set_str_binary (x, "0.101100100000000000110100E7");
77 i = mpfr_tanh (y, x, MPFR_RNDN);
78 if (mpfr_cmp_ui (y, 1) || i != 1)
80 printf("Overflow error (1). i=%d\ny=", i);
84 MPFR_ASSERTN (!mpfr_overflow_p ());
86 i = mpfr_tanh (y, x, MPFR_RNDZ);
87 if (mpfr_cmp_str (y, "0.111111111111111111111111E0", 2, MPFR_RNDN)
90 printf("Overflow error (2).i=%d\ny=", i);
94 MPFR_ASSERTN (!mpfr_overflow_p ());
99 mpfr_set_str_binary (x, "0.1E1000000000");
100 i = mpfr_tanh (y, x, MPFR_RNDN);
101 if (mpfr_cmp_ui (y, 1) || i != 1)
103 printf("Overflow error (3). i=%d\ny=", i);
107 MPFR_ASSERTN (!mpfr_overflow_p ());
108 mpfr_set_str_binary (x, "-0.1E1000000000");
109 i = mpfr_tanh (y, x, MPFR_RNDU);
110 if (mpfr_cmp_str (y, "-0.111111111111111111111111E0", 2, MPFR_RNDN)
113 printf("Overflow error (4). i=%d\ny=", i);
123 main (int argc, char *argv[])
130 test_generic (2, 100, 100);
132 data_check ("data/tanh", mpfr_tanh, "mpfr_tanh");
133 bad_cases (mpfr_tanh, mpfr_atanh, "mpfr_tanh", 256, -128, 0,