4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma weak __ctanhf = ctanhf
32 #include "libm.h" /* expf/expm1f/fabsf/sincosf/sinf/tanhf */
33 #include "complex_wrapper.h"
36 static const float four
= 4.0F
, two
= 2.0F
, one
= 1.0F
, zero
= 0.0F
;
41 float r
, u
, v
, t
, x
, y
, S
, C
;
54 if (iy
== 0) { /* ctanh(x,0) = (x,0) for x = 0 or NaN */
57 } else if (iy
>= 0x7f800000) { /* y is inf or NaN */
58 if (ix
< 0x7f800000) /* catanh(finite x,inf/nan) is nan */
59 F_RE(ans
) = F_IM(ans
) = y
- y
;
60 else if (ix
== 0x7f800000) { /* x is inf */
67 } else if (ix
>= 0x41600000) {
69 * |x| > 14 = prec/2 (14,28,34,60)
70 * ctanh z ~ 1 + i (sin2y)/(exp(2x))
73 if (iy
< 0x7f000000) /* t = sin(2y) */
76 (void) sincosf(y
, &S
, &C
);
79 if (ix
>= 0x7f000000) { /* |x| > max/2 */
80 if (ix
>= 0x7f800000) { /* |x| is inf or NaN */
81 if (ix
> 0x7f800000) /* x is NaN */
82 F_RE(ans
) = F_IM(ans
) = x
+ y
;
84 F_IM(ans
) = zero
* S
; /* x is inf */
86 F_IM(ans
) = S
* expf(-x
); /* underflow */
88 F_IM(ans
) = (S
+ S
) * expf(-(x
+ x
));
89 /* 2 sin 2y / exp(2x) */
94 * ctanh z = ---------------------------
95 * t*t+[4(t+1)(cos y)](cos y)
97 * [4(t+1)(cos y)]*(sin y)
98 * i --------------------------
99 * t*t+[4(t+1)(cos y)](cos y)
102 (void) sincosf(y
, &S
, &C
);
104 r
= (four
* C
) * (t
+ one
);
106 v
= one
/ (u
+ r
* C
);
107 F_RE(ans
) = (u
+ two
* t
) * v
;
108 F_IM(ans
) = (r
* S
) * v
;
111 F_RE(ans
) = -F_RE(ans
);
113 F_IM(ans
) = -F_IM(ans
);