Skip to content

Commit

Permalink
added Macaulay2 patch for llvm@15
Browse files Browse the repository at this point in the history
No new revision is issued since the binaries should be untouched.

The patch is by @jkyang92.
  • Loading branch information
mahrud committed Nov 9, 2023
1 parent 669c11d commit fccc645
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Formula/macaulay2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,51 @@ def install
--
2.40.1

diff --git a/M2/Macaulay2/e/eigen.cpp b/M2/Macaulay2/e/eigen.cpp
index 26cf19de66..77748d5a8c 100644
--- a/M2/Macaulay2/e/eigen.cpp
+++ b/M2/Macaulay2/e/eigen.cpp
@@ -29,6 +29,41 @@ using MatrixXmpRR = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>;
using MatrixXmpCC = Eigen::Matrix<std::complex<double>,Eigen::Dynamic,Eigen::Dynamic>;
#endif

+#ifdef _LIBCPP_VERSION
+/* workaround incompatibility between libc++'s implementation of complex and
+ * mpreal
+ */
+namespace eigen_mpfr {
+inline Real abs(const Complex &x) { return hypot(x.real(), x.imag()); }
+inline Complex sqrt(const Complex &x)
+{
+ Real a = abs(x);
+ const Real &xr = x.real();
+ const Real &xi = x.imag();
+ if (xi >= 0) { return Complex(sqrt((a + xr) / 2), sqrt((a - xr) / 2)); }
+ else { return Complex(sqrt((a + xr) / 2), -sqrt((a - xr) / 2)); }
+}
+inline std::complex<Real> operator/(const Complex &lhs, const Complex &rhs)
+{
+ const Real &lhsr = lhs.real();
+ const Real &lhsi = lhs.imag();
+ const Real &rhsr = rhs.real();
+ const Real &rhsi = rhs.imag();
+ Real normrhs = rhsr*rhsr+rhsi*rhsi;
+ return Complex((lhsr * rhsr + lhsi * rhsi) / normrhs,
+ (lhsi * rhsr - lhsr * rhsi) / normrhs);
+}
+inline std::complex<Real> operator*(const Complex &lhs, const Complex &rhs)
+{
+ const Real &lhsr = lhs.real();
+ const Real &lhsi = lhs.imag();
+ const Real &rhsr = rhs.real();
+ const Real &rhsi = rhs.imag();
+ return Complex(lhsr * rhsr - lhsi * rhsi, lhsi * rhsr + lhsr * rhsi);
+}
+}; // namespace eigen_mpfr
+#endif
+
namespace EigenM2 {

#ifdef NO_LAPACK
--
2.40.1

0 comments on commit fccc645

Please sign in to comment.