OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / uClibc / libm / cexp.c
1 /*
2  * Copyright (c) 2011 William Pitcock <nenolod@dereferenced.org>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18  * POSSIBILITY OF SUCH DAMAGE.
19  */
20
21 #include <features.h>
22 #include <math.h>
23 #include <complex.h>
24
25 __complex__ double cexp(__complex__ double z)
26 {
27         __complex__ double ret;
28         double r_exponent = exp(__real__ z);
29
30         __real__ ret = r_exponent * cos(__imag__ z);
31         __imag__ ret = r_exponent * sin(__imag__ z);
32
33         return ret;
34 }
35 libm_hidden_def(cexp)
36
37 libm_hidden_proto(cexpf)
38 __complex__ float cexpf(__complex__ float z)
39 {
40         __complex__ float ret;
41         double r_exponent = exp(__real__ z);
42
43         __real__ ret = r_exponent * cosf(__imag__ z);
44         __imag__ ret = r_exponent * sinf(__imag__ z);
45
46         return ret;
47 }
48 libm_hidden_def(cexpf)
49
50 #if defined __UCLIBC_HAS_LONG_DOUBLE_MATH__ && !defined __NO_LONG_DOUBLE_MATH
51 libm_hidden_proto(cexpl)
52 __complex__ long double cexpl(__complex__ long double z)
53 {
54         __complex__ long double ret;
55         long double r_exponent = expl(__real__ z);
56
57         __real__ ret = r_exponent * cosl(__imag__ z);
58         __imag__ ret = r_exponent * sinl(__imag__ z);
59
60         return ret;
61 }
62 libm_hidden_def(cexpl)
63 #endif