Skip to content

Commit fccc645

Browse files
committed
added Macaulay2 patch for llvm@15
No new revision is issued since the binaries should be untouched. The patch is by @jkyang92.
1 parent 669c11d commit fccc645

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Formula/macaulay2.rb

+48
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,51 @@ def install
179179
--
180180
2.40.1
181181

182+
diff --git a/M2/Macaulay2/e/eigen.cpp b/M2/Macaulay2/e/eigen.cpp
183+
index 26cf19de66..77748d5a8c 100644
184+
--- a/M2/Macaulay2/e/eigen.cpp
185+
+++ b/M2/Macaulay2/e/eigen.cpp
186+
@@ -29,6 +29,41 @@ using MatrixXmpRR = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>;
187+
using MatrixXmpCC = Eigen::Matrix<std::complex<double>,Eigen::Dynamic,Eigen::Dynamic>;
188+
#endif
189+
190+
+#ifdef _LIBCPP_VERSION
191+
+/* workaround incompatibility between libc++'s implementation of complex and
192+
+ * mpreal
193+
+ */
194+
+namespace eigen_mpfr {
195+
+inline Real abs(const Complex &x) { return hypot(x.real(), x.imag()); }
196+
+inline Complex sqrt(const Complex &x)
197+
+{
198+
+ Real a = abs(x);
199+
+ const Real &xr = x.real();
200+
+ const Real &xi = x.imag();
201+
+ if (xi >= 0) { return Complex(sqrt((a + xr) / 2), sqrt((a - xr) / 2)); }
202+
+ else { return Complex(sqrt((a + xr) / 2), -sqrt((a - xr) / 2)); }
203+
+}
204+
+inline std::complex<Real> operator/(const Complex &lhs, const Complex &rhs)
205+
+{
206+
+ const Real &lhsr = lhs.real();
207+
+ const Real &lhsi = lhs.imag();
208+
+ const Real &rhsr = rhs.real();
209+
+ const Real &rhsi = rhs.imag();
210+
+ Real normrhs = rhsr*rhsr+rhsi*rhsi;
211+
+ return Complex((lhsr * rhsr + lhsi * rhsi) / normrhs,
212+
+ (lhsi * rhsr - lhsr * rhsi) / normrhs);
213+
+}
214+
+inline std::complex<Real> operator*(const Complex &lhs, const Complex &rhs)
215+
+{
216+
+ const Real &lhsr = lhs.real();
217+
+ const Real &lhsi = lhs.imag();
218+
+ const Real &rhsr = rhs.real();
219+
+ const Real &rhsi = rhs.imag();
220+
+ return Complex(lhsr * rhsr - lhsi * rhsi, lhsi * rhsr + lhsr * rhsi);
221+
+}
222+
+}; // namespace eigen_mpfr
223+
+#endif
224+
+
225+
namespace EigenM2 {
226+
227+
#ifdef NO_LAPACK
228+
--
229+
2.40.1

0 commit comments

Comments
 (0)