1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 24 */ 25 26 /* 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 #pragma weak __cexpl = cexpl 32 33 #include "libm.h" /* expl/isinfl/iszerol/scalbnl/sincosl */ 34 #include "complex_wrapper.h" 35 36 extern int isinfl(long double); 37 extern int iszerol(long double); 38 39 static const long double zero = 0.0L; 40 41 42 ldcomplex 43 cexpl(ldcomplex z) 44 { 45 ldcomplex ans; 46 long double x, y, t, c, s; 47 int n, ix, iy, hx, hy; 48 49 x = LD_RE(z); 50 y = LD_IM(z); 51 hx = HI_XWORD(x); 52 hy = HI_XWORD(y); 53 ix = hx & 0x7fffffff; 54 iy = hy & 0x7fffffff; 55 56 if (iszerol(y)) { /* y = 0 */ 57 LD_RE(ans) = expl(x); 58 LD_IM(ans) = y; 59 } else if (isinfl(x)) { /* x is +-inf */ 60 if (hx < 0) { 61 if (iy >= 0x7fff0000) { 62 LD_RE(ans) = zero; 63 LD_IM(ans) = zero; 64 } else { 65 sincosl(y, &s, &c); 66 LD_RE(ans) = zero * c; 67 LD_IM(ans) = zero * s; 68 } 69 } else { 70 if (iy >= 0x7fff0000) { 71 LD_RE(ans) = x; 72 LD_IM(ans) = y - y; 73 } else { 74 (void) sincosl(y, &s, &c); 75 LD_RE(ans) = x * c; 76 LD_IM(ans) = x * s; 77 } 78 } 79 } else { 80 (void) sincosl(y, &s, &c); 81 82 if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */ 83 t = __k_cexpl(x, &n); 84 LD_RE(ans) = scalbnl(t * c, n); 85 LD_IM(ans) = scalbnl(t * s, n); 86 } else { 87 t = expl(x); 88 LD_RE(ans) = t * c; 89 LD_IM(ans) = t * s; 90 } 91 } 92 93 return (ans); 94 }