freebsd-ports/audio/moony-lv2/files/patch-lcomplex_lcomplex.c
Yuri Victorovich 47d7ed77e5 audio/moony-lv2: Unbreak on 12
Due to bug#221341 cpow/clog functions are missing, and were implemented ad-hoc in the patch.
Recently clog has been added to 12 in r333577, which conflited with the ad-hoc implementation of clog in the patch.
To correct this, cmake-level cpow/clog detection were added, and ad-hoc implementations are now added
only when cpow/clog aren't present in the system.
2018-05-19 07:32:26 +00:00

47 lines
1.1 KiB
C

--- lcomplex/lcomplex.c.orig 2017-05-16 21:46:21 UTC
+++ lcomplex/lcomplex.c
@@ -7,6 +7,7 @@
*/
#include <complex.h>
+#include <math.h>
#include "lua.h"
#include "lauxlib.h"
@@ -78,6 +79,36 @@ static int Ltostring(lua_State *L) /**
return 1;
}
+#if !defined(FreeBSD_CLOG_EXISTS)
+// Missing C99 functions clog and cpow: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221341
+static Complex clog(Complex z) {return log(cabs(z)) + I * carg(z);}
+#endif
+#if !defined(FreeBSD_CPOW_EXISTS)
+// from https://github.com/eblot/newlib/blob/master/newlib/libm/complex/cpow.c
+static Complex
+cpow(Complex a, Complex z)
+{
+ double complex w;
+ double x, y, r, theta, absa, arga;
+
+ x = creal(z);
+ y = cimag(z);
+ absa = cabs(a);
+ if (absa == 0.0) {
+ return (0.0 + 0.0 * I);
+ }
+ arga = carg(a);
+ r = pow(absa, x);
+ theta = x * arga;
+ if (y != 0.0) {
+ r = r * exp(-y * arga);
+ theta = theta + y * log(absa);
+ }
+ w = r * cos(theta) + (r * sin(theta)) * I;
+ return w;
+}
+#endif
+
#define A(f,e) static int L##f(lua_State *L) { return pushcomplex(L,e); }
#define B(f) A(f,l_mathop(c##f)(Z(1),Z(2)))
#define F(f) A(f,l_mathop(c##f)(Z(1)))