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 2005 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 #pragma weak __cexpf = cexpf 32 33 #include "libm.h" 34 #include "complex_wrapper.h" 35 36 #if defined(__i386) && !defined(__amd64) 37 extern int __swapRP(int); 38 #endif 39 40 static const float zero = 0.0F; 41 42 fcomplex 43 cexpf(fcomplex z) 44 { 45 fcomplex ans; 46 float x, y, c, s; 47 double t; 48 int n, ix, iy, hx, hy; 49 50 x = F_RE(z); 51 y = F_IM(z); 52 hx = THE_WORD(x); 53 hy = THE_WORD(y); 54 ix = hx & 0x7fffffff; 55 iy = hy & 0x7fffffff; 56 57 if (iy == 0) { /* y = 0 */ 58 F_RE(ans) = expf(x); 59 F_IM(ans) = y; 60 } else if (ix == 0x7f800000) { /* x is +-inf */ 61 if (hx < 0) { 62 if (iy >= 0x7f800000) { 63 F_RE(ans) = zero; 64 F_IM(ans) = zero; 65 } else { 66 sincosf(y, &s, &c); 67 F_RE(ans) = zero * c; 68 F_IM(ans) = zero * s; 69 } 70 } else { 71 if (iy >= 0x7f800000) { 72 F_RE(ans) = x; 73 F_IM(ans) = y - y; 74 } else { 75 sincosf(y, &s, &c); 76 F_RE(ans) = x * c; 77 F_IM(ans) = x * s; 78 } 79 } 80 } else { 81 sincosf(y, &s, &c); 82 83 if (ix >= 0x42B171AA) { /* |x| > 88.722... ~ log(2**128) */ 84 #if defined(__i386) && !defined(__amd64) 85 int rp = __swapRP(fp_extended); 86 #endif 87 t = __k_cexp(x, &n); 88 F_RE(ans) = (float)scalbn(t * (double)c, n); 89 F_IM(ans) = (float)scalbn(t * (double)s, n); 90 #if defined(__i386) && !defined(__amd64) 91 if (rp != fp_extended) 92 (void) __swapRP(rp); 93 #endif 94 } else { 95 t = expf(x); 96 F_RE(ans) = t * c; 97 F_IM(ans) = t * s; 98 } 99 } 100 101 return (ans); 102 }