advanpix / mpreal

GNU General Public License v3.0
84 stars 19 forks source link

Possible compatibility issue with MPFR 4.2.1 #24

Open gauravharsha opened 11 months ago

gauravharsha commented 11 months ago

This rudimentary code uses mpreal.h and MPFR libraries for C++. When compiling with

it works perfectly fine. But after updating my libraries to

the compiler raises multiple errors related to, I believe, method inheritance. For instance, the Clang 15 and MPFR-4.2.1 combo raises some of the following errors (among other similar ones):

  1. Dividing two multi-precision templated variables raises the compile-time error
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:706:63: error: no matching function for call to '__constexpr_fabs'
  2. In other places, a division leads to the error
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:607:12: error: no matching function for call to 'isinf'

It is not unlikely that there are problems with the code itself, but the sudden breakdown of the attached code after updating the mpfr library makes me think there could be some incompatibilities introduced in the update. I would appreciate any valuable feedback.

PS: The link appears to be broken. I will instead try to share a simple example.

advanpix commented 11 months ago

Recently introduced C++23 features seem to cause these errors. Please compile the code in C++11 or similar mode.

gauravharsha commented 11 months ago

I am using --std=c++11 in compile flags (or equivalently, using set(CMAKE_CXX_STANDARD 11) in my CMakeLists.txt file. However, the error persists. As promised, here is a sample code:

#include <iostream>
#include <complex>
#include <gmpxx.h>
#include <mpreal.h>

using namespace mpfr;

int main(int argc, char * argv[]) {
  // Set precision
  mpreal::set_default_prec(128);
  // define two complex numbers
  std::complex<mpreal> a {1.0, 0.0};
  std::complex<mpreal> b {0.0, 1.0};
  // divide a by b
  std::complex<mpreal> c;
  c = a / b;
  std::cout << "a / b = " << c;
  return 0;
}

The corresponding CMakeLists.txt file is:

cmake_minimum_required(VERSION 3.11)
project(test_mpreal)

set(CMAKE_CXX_STANDARD 11)
#set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

find_package(GMP REQUIRED)
find_package(MPFR REQUIRED)

INCLUDE_DIRECTORIES(
        "${GMP_INCLUDES}"
        "${CMAKE_SOURCE_DIR}"
)

add_executable(test_mpreal main.cpp)
target_link_libraries(test_mpreal ${MPFR_LIBRARIES} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
target_link_libraries(test_mpreal ${MPFR_LIBRARIES} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})

The output from cmake is:

-- The C compiler identification is AppleClang 15.0.0.15000040
-- The CXX compiler identification is AppleClang 15.0.0.15000040
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GMP: /usr/local/include
-- Found MPFR: /usr/local/include (Required is at least version "1.0.0")
-- GMPXX_INCLUDES=/usr/local/include
-- Configuring done (2.5s)
-- Generating done (0.0s)

Library versions:

Perhaps I'm missing something obvious here? The code compiled with older MPFR libraries, but does not do so after recent updates.

cielavenir commented 3 months ago

I (jfyi my company bought mpreal license) had a similar problem but my issue was my mpreal revision was before 269a03782fa0b87c20470976b88677266c5423ad . After updating I don't see such error.

I wonder if gauravharsha's mpreal revision was old.