xref: /titanic_41/usr/src/lib/libm/common/complex/csinhf.c (revision a9d3dcd5820128b4f34bf38f447e47aa95c004e8)
15b2ba9d3SPiotr Jasiukajtis /*
25b2ba9d3SPiotr Jasiukajtis  * CDDL HEADER START
35b2ba9d3SPiotr Jasiukajtis  *
45b2ba9d3SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
55b2ba9d3SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
65b2ba9d3SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
75b2ba9d3SPiotr Jasiukajtis  *
85b2ba9d3SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95b2ba9d3SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
105b2ba9d3SPiotr Jasiukajtis  * See the License for the specific language governing permissions
115b2ba9d3SPiotr Jasiukajtis  * and limitations under the License.
125b2ba9d3SPiotr Jasiukajtis  *
135b2ba9d3SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
145b2ba9d3SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155b2ba9d3SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
165b2ba9d3SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
175b2ba9d3SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
185b2ba9d3SPiotr Jasiukajtis  *
195b2ba9d3SPiotr Jasiukajtis  * CDDL HEADER END
205b2ba9d3SPiotr Jasiukajtis  */
215b2ba9d3SPiotr Jasiukajtis /*
225b2ba9d3SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
235b2ba9d3SPiotr Jasiukajtis  */
245b2ba9d3SPiotr Jasiukajtis /*
255b2ba9d3SPiotr Jasiukajtis  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
265b2ba9d3SPiotr Jasiukajtis  * Use is subject to license terms.
275b2ba9d3SPiotr Jasiukajtis  */
285b2ba9d3SPiotr Jasiukajtis 
29*a9d3dcd5SRichard Lowe #pragma weak __csinhf = csinhf
305b2ba9d3SPiotr Jasiukajtis 
315b2ba9d3SPiotr Jasiukajtis #include "libm.h"
325b2ba9d3SPiotr Jasiukajtis #include "complex_wrapper.h"
335b2ba9d3SPiotr Jasiukajtis 
345b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
355b2ba9d3SPiotr Jasiukajtis extern int __swapRP(int);
365b2ba9d3SPiotr Jasiukajtis #endif
375b2ba9d3SPiotr Jasiukajtis 
385b2ba9d3SPiotr Jasiukajtis static const float zero = 0.0F, half = 0.5F;
395b2ba9d3SPiotr Jasiukajtis 
405b2ba9d3SPiotr Jasiukajtis fcomplex
csinhf(fcomplex z)415b2ba9d3SPiotr Jasiukajtis csinhf(fcomplex z) {
425b2ba9d3SPiotr Jasiukajtis 	float		x, y, S, C;
435b2ba9d3SPiotr Jasiukajtis 	double		t;
445b2ba9d3SPiotr Jasiukajtis 	int		hx, ix, hy, iy, n;
455b2ba9d3SPiotr Jasiukajtis 	fcomplex	ans;
465b2ba9d3SPiotr Jasiukajtis 
475b2ba9d3SPiotr Jasiukajtis 	x = F_RE(z);
485b2ba9d3SPiotr Jasiukajtis 	y = F_IM(z);
495b2ba9d3SPiotr Jasiukajtis 	hx = THE_WORD(x);
505b2ba9d3SPiotr Jasiukajtis 	ix = hx & 0x7fffffff;
515b2ba9d3SPiotr Jasiukajtis 	hy = THE_WORD(y);
525b2ba9d3SPiotr Jasiukajtis 	iy = hy & 0x7fffffff;
535b2ba9d3SPiotr Jasiukajtis 	x = fabsf(x);
545b2ba9d3SPiotr Jasiukajtis 	y = fabsf(y);
555b2ba9d3SPiotr Jasiukajtis 
565b2ba9d3SPiotr Jasiukajtis 	sincosf(y, &S, &C);
575b2ba9d3SPiotr Jasiukajtis 	if (ix >= 0x41600000) {	/* |x| > 14 = prec/2 (14,28,34,60) */
585b2ba9d3SPiotr Jasiukajtis 		if (ix >= 0x42B171AA) {	/* |x| > 88.722... ~ log(2**128) */
595b2ba9d3SPiotr Jasiukajtis 			if (ix >= 0x7f800000) {	/* |x| is inf or NaN */
605b2ba9d3SPiotr Jasiukajtis 				if (iy == 0) {
615b2ba9d3SPiotr Jasiukajtis 					F_RE(ans) = x;
625b2ba9d3SPiotr Jasiukajtis 					F_IM(ans) = y;
635b2ba9d3SPiotr Jasiukajtis 				} else if (iy >= 0x7f800000) {
645b2ba9d3SPiotr Jasiukajtis 					F_RE(ans) = x;
655b2ba9d3SPiotr Jasiukajtis 					F_IM(ans) = x - y;
665b2ba9d3SPiotr Jasiukajtis 				} else {
675b2ba9d3SPiotr Jasiukajtis 					F_RE(ans) = C * x;
685b2ba9d3SPiotr Jasiukajtis 					F_IM(ans) = S * x;
695b2ba9d3SPiotr Jasiukajtis 				}
705b2ba9d3SPiotr Jasiukajtis 			} else {
715b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
725b2ba9d3SPiotr Jasiukajtis 				int	rp = __swapRP(fp_extended);
735b2ba9d3SPiotr Jasiukajtis #endif
745b2ba9d3SPiotr Jasiukajtis 				/* return (C, S) * exp(x) / 2 */
755b2ba9d3SPiotr Jasiukajtis 				t = __k_cexp((double)x, &n);
765b2ba9d3SPiotr Jasiukajtis 				F_RE(ans) = (float)scalbn(C * t, n - 1);
775b2ba9d3SPiotr Jasiukajtis 				F_IM(ans) = (float)scalbn(S * t, n - 1);
785b2ba9d3SPiotr Jasiukajtis #if defined(__i386) && !defined(__amd64)
795b2ba9d3SPiotr Jasiukajtis 				if (rp != fp_extended)
805b2ba9d3SPiotr Jasiukajtis 					(void) __swapRP(rp);
815b2ba9d3SPiotr Jasiukajtis #endif
825b2ba9d3SPiotr Jasiukajtis 			}
835b2ba9d3SPiotr Jasiukajtis 		} else {
845b2ba9d3SPiotr Jasiukajtis 			t = expf(x) * half;
855b2ba9d3SPiotr Jasiukajtis 			F_RE(ans) = C * t;
865b2ba9d3SPiotr Jasiukajtis 			F_IM(ans) = S * t;
875b2ba9d3SPiotr Jasiukajtis 		}
885b2ba9d3SPiotr Jasiukajtis 	} else {
895b2ba9d3SPiotr Jasiukajtis 		if (ix == 0) {	/* x = 0, return (0,S) */
905b2ba9d3SPiotr Jasiukajtis 			F_RE(ans) = zero;
915b2ba9d3SPiotr Jasiukajtis 			F_IM(ans) = S;
925b2ba9d3SPiotr Jasiukajtis 		} else {
935b2ba9d3SPiotr Jasiukajtis 			F_RE(ans) = C * sinhf(x);
945b2ba9d3SPiotr Jasiukajtis 			F_IM(ans) = S * coshf(x);
955b2ba9d3SPiotr Jasiukajtis 		}
965b2ba9d3SPiotr Jasiukajtis 	}
975b2ba9d3SPiotr Jasiukajtis 	if (hx < 0)
985b2ba9d3SPiotr Jasiukajtis 		F_RE(ans) = -F_RE(ans);
995b2ba9d3SPiotr Jasiukajtis 	if (hy < 0)
1005b2ba9d3SPiotr Jasiukajtis 		F_IM(ans) = -F_IM(ans);
1015b2ba9d3SPiotr Jasiukajtis 	return (ans);
1025b2ba9d3SPiotr Jasiukajtis }
103