xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tsinh.c (revision eceb233b9bd0dfebb902ed73b531ae6964fa3f9b)
1 /* Test file for mpfr_sinh.
2 
3 Copyright 2001-2002, 2004, 2006-2018 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 http://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_sinh
26 #define TEST_RANDOM_EMIN -36
27 #define TEST_RANDOM_EMAX 36
28 #include "tgeneric.c"
29 
30 static void
31 special (void)
32 {
33   mpfr_t x;
34   int i;
35 
36   mpfr_init (x);
37 
38   mpfr_set_nan (x);
39   mpfr_sinh (x, x, MPFR_RNDN);
40   MPFR_ASSERTN(mpfr_nan_p (x));
41 
42   mpfr_set_inf (x, 1);
43   mpfr_sinh (x, x, MPFR_RNDN);
44   MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
45   mpfr_set_inf (x, -1);
46   mpfr_sinh (x, x, MPFR_RNDN);
47   MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
48 
49   mpfr_set_prec (x, 10);
50   mpfr_set_str_binary (x, "-0.1001011001");
51   mpfr_sinh (x, x, MPFR_RNDN);
52   MPFR_ASSERTN(mpfr_cmp_si_2exp (x, -159, -8) == 0);
53 
54   /* corner case */
55   mpfr_set_prec (x, 2);
56   mpfr_set_str_binary (x, "1E-6");
57   mpfr_sinh (x, x, MPFR_RNDN);
58   MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, -6) == 0);
59 
60   mpfr_clear_flags ();
61   mpfr_set_str_binary (x, "1E1000000000");
62   i = mpfr_sinh (x, x, MPFR_RNDN);
63   MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_POS (x));
64   MPFR_ASSERTN (mpfr_overflow_p ());
65   MPFR_ASSERTN (i == 1);
66 
67   mpfr_clear_flags ();
68   mpfr_set_str_binary (x, "-1E1000000000");
69   i = mpfr_sinh (x, x, MPFR_RNDN);
70   MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_NEG (x));
71   MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ());
72   MPFR_ASSERTN (i == -1);
73 
74   mpfr_clear_flags ();
75   mpfr_set_str_binary (x, "-1E1000000000");
76   i = mpfr_sinh (x, x, MPFR_RNDD);
77   MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_NEG (x));
78   MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ());
79   MPFR_ASSERTN (i == -1);
80 
81   mpfr_clear_flags ();
82   mpfr_set_str_binary (x, "-1E1000000000");
83   i = mpfr_sinh (x, x, MPFR_RNDU);
84   MPFR_ASSERTN (!MPFR_IS_INF (x) && MPFR_IS_NEG (x));
85   MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ());
86   MPFR_ASSERTN (i == 1);
87 
88   mpfr_clear (x);
89 }
90 
91 int
92 main (int argc, char *argv[])
93 {
94   tests_start_mpfr ();
95 
96   special ();
97 
98   test_generic (MPFR_PREC_MIN, 100, 100);
99 
100   data_check ("data/sinh", mpfr_sinh, "mpfr_sinh");
101   bad_cases (mpfr_sinh, mpfr_asinh, "mpfr_sinh", 256, -256, 255,
102              4, 128, 800, 100);
103 
104   tests_end_mpfr ();
105   return 0;
106 }
107