summaryrefslogtreecommitdiffstats
path: root/main/libc0.9.32/0015-libm-implement-generic-cexp-cexpf-and-cexpl.patch
blob: 1ac2316580b1169f101bc2ddc0b513a76b1aa672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
From bf95401faf3ec57b5f45ada41dc219f6d04770ae Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Tue, 1 Nov 2011 18:41:30 -0500
Subject: [PATCH] libm: implement generic cexp(), cexpf() and cexpl().

The cexp*() family of functions is defined by the C99 math standard as
implementing exponential functions for complex types.

Signed-off-by: William Pitcock <nenolod@dereferenced.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
(cherry picked from commit 6471fc450b66dcb1ba16fe6568cd52221ca64cd1)
---
 libm/Makefile.in |    3 +-
 libm/cexp.c      |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletions(-)
 create mode 100644 libm/cexp.c

diff --git a/libm/Makefile.in b/libm/Makefile.in
index f0aaa2a..af949e8 100644
--- a/libm/Makefile.in
+++ b/libm/Makefile.in
@@ -72,7 +72,8 @@ libm_CSRC := \
 	s_fpclassify.c s_fpclassifyf.c s_signbit.c s_signbitf.c \
 	s_isnan.c s_isnanf.c s_isinf.c s_isinff.c s_finitef.c \
 	s_fdim.c s_fma.c s_fmax.c s_fmin.c \
-	s_remquo.c w_exp2.c
+	s_remquo.c w_exp2.c \
+	cexp.c
 
 # Not implemented [yet?], see comment in float_wrappers.c:
 # fdimf.o fmaf.o fmaxf.o fminf.o
diff --git a/libm/cexp.c b/libm/cexp.c
new file mode 100644
index 0000000..87512b7
--- /dev/null
+++ b/libm/cexp.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011 William Pitcock <nenolod@dereferenced.org>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <features.h>
+#include <math.h>
+#include <complex.h>
+
+__complex__ double cexp(__complex__ double z)
+{
+	__complex__ double ret;
+	double r_exponent = exp(__real__ z);
+
+	__real__ ret = r_exponent * cos(__imag__ z);
+	__imag__ ret = r_exponent * sin(__imag__ z);
+
+	return ret;
+}
+libm_hidden_def(cexp)
+
+libm_hidden_proto(cexpf)
+__complex__ float cexpf(__complex__ float z)
+{
+	__complex__ float ret;
+	double r_exponent = exp(__real__ z);
+
+	__real__ ret = r_exponent * cosf(__imag__ z);
+	__imag__ ret = r_exponent * sinf(__imag__ z);
+
+	return ret;
+}
+libm_hidden_def(cexpf)
+
+#if defined __UCLIBC_HAS_LONG_DOUBLE_MATH__ && !defined __NO_LONG_DOUBLE_MATH
+libm_hidden_proto(cexpl)
+__complex__ long double cexpl(__complex__ long double z)
+{
+	__complex__ long double ret;
+	long double r_exponent = expl(__real__ z);
+
+	__real__ ret = r_exponent * cosl(__imag__ z);
+	__imag__ ret = r_exponent * sinl(__imag__ z);
+
+	return ret;
+}
+libm_hidden_def(cexpl)
+#endif
-- 
1.7.8