From: Markus Blatt <markus@dr-blatt.de>
Date: Wed, 17 Sep 2025 18:55:59 +0200
Subject: Deactivate further overloads for __float128 if it is long double.

This fixes compilation on pc64el.
---
 cmake/Modules/FindQuadMath.cmake | 16 +++++++++++++++-
 opm/material/common/quad.hpp     | 10 +++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/cmake/Modules/FindQuadMath.cmake b/cmake/Modules/FindQuadMath.cmake
index 7712379..96873f6 100644
--- a/cmake/Modules/FindQuadMath.cmake
+++ b/cmake/Modules/FindQuadMath.cmake
@@ -55,8 +55,22 @@ if(QuadMath_FOUND AND NOT TARGET QuadMath::QuadMath)
      static_assert(std::numeric_limits<__float128>::is_specialized);
      return 0;
   }" QuadMath_HAS_LIMITS)
-  cmake_pop_check_state()  # Reset CMAKE_REQUIRED_XXX variables
+
   if(QuadMath_HAS_LIMITS)
     target_compile_definitions(QuadMath::QuadMath INTERFACE LIMITS_HAS_QUAD=1)
   endif()
+  check_cxx_source_compiles("
+  #include <limits>
+  #include <iostream>
+  int main()
+  {
+     __float128 b=0;
+     std::cout<<b;
+     return 0;
+  }" QuadMath_HAS_IO_OPERATOR)
+  cmake_pop_check_state()  # Reset CMAKE_REQUIRED_XXX variables
+  if(QuadMath_HAS_IO_OPERATOR)
+    target_compile_definitions(QuadMath::QuadMath INTERFACE QUADMATH_HAS_IO_OPERATOR=1)
+  endif()
+
 endif()
diff --git a/opm/material/common/quad.hpp b/opm/material/common/quad.hpp
index cd32c71..9f4c10a 100644
--- a/opm/material/common/quad.hpp
+++ b/opm/material/common/quad.hpp
@@ -246,6 +246,7 @@ struct is_convertible<quad, OtherType>
     : public is_arithmetic<OtherType>
 { };
 
+#if !QUADMATH_HAS_IO_OPERATOR
 inline std::ostream& operator<<(std::ostream& os, const quad& val)
 {
     if (os.precision() > std::numeric_limits<double>::digits10)
@@ -256,13 +257,14 @@ inline std::ostream& operator<<(std::ostream& os, const quad& val)
     return os << static_cast<double>(val);
 }
 
-inline std::istream& operator>>(std::istream& is, quad& val)
+inline typename std::istream& operator>>(std::istream& is, quad& val)
 {
     double tmp = 0.0;
     std::istream& ret = (is >> tmp);
     val = tmp;
     return ret;
 }
+#endif
 
 inline quad real(quad val)
 { return val; }
@@ -276,6 +278,7 @@ inline quad imag(quad)
 inline quad imag(const std::complex<quad>& val)
 { return val.imag(); }
 
+#if !LIMITS_HAS_QUAD
 inline quad abs(quad val)
 { return (val < 0) ? -val : val; }
 
@@ -284,6 +287,7 @@ inline quad floor(quad val)
 
 inline quad ceil(quad val)
 { return ceilq(val); }
+#endif
 
 inline quad max(quad a, quad b)
 { return (a > b) ? a : b; }
@@ -291,8 +295,10 @@ inline quad max(quad a, quad b)
 inline quad min(quad a, quad b)
 { return (a < b) ? a : b; }
 
+#if !LIMITS_HAS_QUAD
 inline quad sqrt(quad val)
 { return sqrtq(val); }
+#endif
 
 template <class ExpType>
 inline quad pow(quad base, ExpType exp)
@@ -302,6 +308,7 @@ template <class BaseType>
 inline quad pow(BaseType base, quad exp)
 { return powq(static_cast<quad>(base), exp); }
 
+#if !LIMITS_HAS_QUAD
 inline quad pow(quad base, quad exp)
 { return powq(base, exp); }
 
@@ -337,6 +344,7 @@ inline bool isnan(quad val)
 
 inline bool isinf(quad val)
 { return isinfq(val); }
+#endif
 
 } // namespace std
 
