diff --git a/Formula/macaulay2.rb b/Formula/macaulay2.rb index c1d1ef9..aeab187 100644 --- a/Formula/macaulay2.rb +++ b/Formula/macaulay2.rb @@ -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; + using MatrixXmpCC = Eigen::Matrix,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 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 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