1*9d8b5fa7Sdrochner /* $NetBSD: ctanhf.c,v 1.1 2007/08/20 16:01:38 drochner Exp $ */
2*9d8b5fa7Sdrochner
3*9d8b5fa7Sdrochner /*-
4*9d8b5fa7Sdrochner * Copyright (c) 2007 The NetBSD Foundation, Inc.
5*9d8b5fa7Sdrochner * All rights reserved.
6*9d8b5fa7Sdrochner *
7*9d8b5fa7Sdrochner * This code is derived from software written by Stephen L. Moshier.
8*9d8b5fa7Sdrochner * It is redistributed by the NetBSD Foundation by permission of the author.
9*9d8b5fa7Sdrochner *
10*9d8b5fa7Sdrochner * Redistribution and use in source and binary forms, with or without
11*9d8b5fa7Sdrochner * modification, are permitted provided that the following conditions
12*9d8b5fa7Sdrochner * are met:
13*9d8b5fa7Sdrochner * 1. Redistributions of source code must retain the above copyright
14*9d8b5fa7Sdrochner * notice, this list of conditions and the following disclaimer.
15*9d8b5fa7Sdrochner * 2. Redistributions in binary form must reproduce the above copyright
16*9d8b5fa7Sdrochner * notice, this list of conditions and the following disclaimer in the
17*9d8b5fa7Sdrochner * documentation and/or other materials provided with the distribution.
18*9d8b5fa7Sdrochner *
19*9d8b5fa7Sdrochner * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*9d8b5fa7Sdrochner * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*9d8b5fa7Sdrochner * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*9d8b5fa7Sdrochner * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*9d8b5fa7Sdrochner * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*9d8b5fa7Sdrochner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*9d8b5fa7Sdrochner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*9d8b5fa7Sdrochner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*9d8b5fa7Sdrochner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*9d8b5fa7Sdrochner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*9d8b5fa7Sdrochner * POSSIBILITY OF SUCH DAMAGE.
30*9d8b5fa7Sdrochner */
31*9d8b5fa7Sdrochner
32*9d8b5fa7Sdrochner #include "../src/namespace.h"
33*9d8b5fa7Sdrochner #include <complex.h>
34*9d8b5fa7Sdrochner #include <math.h>
35*9d8b5fa7Sdrochner
36*9d8b5fa7Sdrochner float complex
ctanhf(float complex z)37*9d8b5fa7Sdrochner ctanhf(float complex z)
38*9d8b5fa7Sdrochner {
39*9d8b5fa7Sdrochner float complex w;
40*9d8b5fa7Sdrochner float x, y, d;
41*9d8b5fa7Sdrochner
42*9d8b5fa7Sdrochner x = crealf(z);
43*9d8b5fa7Sdrochner y = cimagf(z);
44*9d8b5fa7Sdrochner d = coshf(2.0f * x) + cosf(2.0f * y);
45*9d8b5fa7Sdrochner w = sinhf(2.0f * x) / d + (sinf(2.0f * y) / d) * I;
46*9d8b5fa7Sdrochner
47*9d8b5fa7Sdrochner return w;
48*9d8b5fa7Sdrochner }
49