105a0b428SJohn Marino /*	$OpenBSD: s_cacoshf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $	*/
205a0b428SJohn Marino /*
305a0b428SJohn Marino  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
405a0b428SJohn Marino  *
505a0b428SJohn Marino  * Permission to use, copy, modify, and distribute this software for any
605a0b428SJohn Marino  * purpose with or without fee is hereby granted, provided that the above
705a0b428SJohn Marino  * copyright notice and this permission notice appear in all copies.
805a0b428SJohn Marino  *
905a0b428SJohn Marino  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1005a0b428SJohn Marino  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1105a0b428SJohn Marino  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1205a0b428SJohn Marino  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1305a0b428SJohn Marino  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1405a0b428SJohn Marino  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1505a0b428SJohn Marino  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1605a0b428SJohn Marino  */
1705a0b428SJohn Marino 
1805a0b428SJohn Marino /*							cacoshf
1905a0b428SJohn Marino  *
2005a0b428SJohn Marino  *	Complex inverse hyperbolic cosine
2105a0b428SJohn Marino  *
2205a0b428SJohn Marino  *
2305a0b428SJohn Marino  *
2405a0b428SJohn Marino  * SYNOPSIS:
2505a0b428SJohn Marino  *
2605a0b428SJohn Marino  * float complex cacoshf();
2705a0b428SJohn Marino  * float complex z, w;
2805a0b428SJohn Marino  *
2905a0b428SJohn Marino  * w = cacoshf (z);
3005a0b428SJohn Marino  *
3105a0b428SJohn Marino  *
3205a0b428SJohn Marino  *
3305a0b428SJohn Marino  * DESCRIPTION:
3405a0b428SJohn Marino  *
3505a0b428SJohn Marino  * acosh z = i acos z .
3605a0b428SJohn Marino  *
3705a0b428SJohn Marino  * ACCURACY:
3805a0b428SJohn Marino  *
3905a0b428SJohn Marino  *                      Relative error:
4005a0b428SJohn Marino  * arithmetic   domain     # trials      peak         rms
4105a0b428SJohn Marino  *    IEEE      -10,+10     30000       1.6e-14     2.1e-15
4205a0b428SJohn Marino  *
4305a0b428SJohn Marino  */
4405a0b428SJohn Marino 
4505a0b428SJohn Marino #include <complex.h>
4605a0b428SJohn Marino #include <math.h>
4705a0b428SJohn Marino 
4805a0b428SJohn Marino float complex
cacoshf(float complex z)4905a0b428SJohn Marino cacoshf(float complex z)
5005a0b428SJohn Marino {
5105a0b428SJohn Marino 	float complex w;
52*9a1d0688SJohn Marino 	float rx, ry;
5305a0b428SJohn Marino 
54*9a1d0688SJohn Marino 	w = cacosf (z);
55*9a1d0688SJohn Marino 	rx = crealf (w);
56*9a1d0688SJohn Marino 	ry = cimagf (w);
57*9a1d0688SJohn Marino 	if (isnan(rx) && isnan(ry))
58*9a1d0688SJohn Marino 		return (CMPLXF(ry, rx));
59*9a1d0688SJohn Marino 	if (isnan(rx))
60*9a1d0688SJohn Marino 		return (CMPLXF(fabsf(ry), rx));
61*9a1d0688SJohn Marino 	if (isnan(ry))
62*9a1d0688SJohn Marino 		return (CMPLXF(ry, ry));
63*9a1d0688SJohn Marino 	return (CMPLXF(fabsf(ry), copysignf(rx, cimagf(z))));
6405a0b428SJohn Marino }
65