1 /* $OpenBSD: s_ctanf.c,v 1.2 2011/07/20 19:28:33 martynas Exp $ */
3 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * Complex circular tangent
41 * w = --------------------.
44 * On the real axis the denominator is zero at odd multiples
45 * of PI/2. The denominator is evaluated by its Taylor
46 * series near these points.
52 * arithmetic domain # trials peak rms
53 * IEEE -10,+10 30000 3.3e-7 5.1e-8
59 #define MACHEPF 3.0e-8
60 #define MAXNUMF 1.0e38f
62 static const double DP1 = 3.140625;
63 static const double DP2 = 9.67502593994140625E-4;
64 static const double DP3 = 1.509957990978376432E-7;
79 i = t; /* the multiple */
81 t = ((x - t * DP1) - t * DP2) - t * DP3;
85 /* Taylor series expansion for cosh(2y) - cos(2x) */
88 _ctansf(float complex z)
90 float f, x, x2, y, y2, rn, t, d;
92 x = fabsf(2.0f * crealf(z));
93 y = fabsf(2.0f * cimagf(z));
125 while (fabsf(t/d) > MACHEPF)
131 ctanf(float complex z)
136 d = cosf( 2.0f * crealf(z) ) + coshf( 2.0f * cimagf(z) );
142 /*mtherr( "ctanf", OVERFLOW );*/
143 w = MAXNUMF + MAXNUMF * I;
146 w = sinf (2.0f * crealf(z)) / d + (sinhf (2.0f * cimagf(z)) / d) * I;