cexpf.c
1 /* 2 * Copyright (C) 2008-2020 Advanced Micro Devices, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, 7 * this list of conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, 9 * this list of conditions and the following disclaimer in the documentation 10 * and/or other materials provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors 12 * may be used to endorse or promote products derived from this software without 13 * specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 21 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * 26 */ 27 28 #include <libm_macros.h> 29 #include <libm_special.h> 30 #include <libm/amd_funcs_internal.h> 31 #include <libm/types.h> 32 #include <libm/constants.h> 33 34 fc32_t 35 ALM_PROTO_REF(cexpf)(fc32_t z) 36 { 37 flt32u_t re, im; 38 f32_t zy_re, zy_im; 39 40 re.f = creal(z); 41 im.f = cimag(z); 42 43 if((re.i & ALM_F32_SIGN_MASK) == 0) { 44 if((im.i & ALM_F32_SIGN_MASK) == 0) { 45 zy_re = 1.0f; 46 zy_im = 0.0f; 47 } else { 48 ALM_PROTO(sincosf)(im.f, &zy_im, &zy_re); 49 } 50 } else { 51 if((im.i & ALM_F32_SIGN_MASK) == 0) { 52 zy_re = ALM_PROTO(expf)(re.f); 53 zy_im = 0.0f; 54 } else { 55 f32_t t = ALM_PROTO(expf)(re.f); 56 ALM_PROTO(sincosf)(im.f, &zy_im, &zy_re); 57 zy_re *= t; 58 zy_im *= t; 59 } 60 61 } 62 63 return zy_re + I*zy_im; 64 } 65