xref: /original-bsd/usr.bin/f77/libF77/CCI/tanh.c (revision 990ad5b1)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Computer Consoles Inc.
7  *
8  * %sccs.include.proprietary.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)tanh.c	5.2 (Berkeley) 04/12/91";
13 #endif /* not lint */
14 
15 /*
16 	tanh(arg) computes the hyperbolic tangent of its floating
17 	point argument.
18 
19 	sinh and cosh are called except for large arguments, which
20 	would cause overflow improperly.
21 */
22 
23 double sinh(), cosh();
24 
25 double
26 tanh(arg)
27 double arg;
28 {
29 	double sign;
30 
31 	sign = 1.;
32 	if(arg < 0.){
33 		arg = -arg;
34 		sign = -1.;
35 	}
36 
37 	if(arg > 21.)
38 		return(sign);
39 
40 	return(sign*sinh(arg)/cosh(arg));
41 }
42