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