From bbce4a875b5ec91b42c23fd2e29e22e79553ba5a Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:01:13 +0200 Subject: [PATCH 01/51] Added CMake options from autoconf and find-package Find*.cmake files --- CMakeLists.txt | 72 +++++++++++++++++++++++++++++++++++++++++++++ FindGMP.cmake | 61 +++++++++++++++++++++++++++++++++++++++ FindMySQL.cmake | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 FindGMP.cmake create mode 100644 FindMySQL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f38613e..bfcdc95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,78 @@ include(CTest) include(c) +set(CMAKE_MODULE_PATH ".") + +option(WITH_GMP "use GNU MP bignum library" OFF) +if(WITH_GMP) + find_package(GMP) + if(GMP_FOUND) + target_include_directories(GLPK GMP_INCLUDE_DIRS) + target_link_libraries(GLPK GMP_LIBRARIES) + else() + message(FATAL_ERROR "gmp.h/libgmp not found") + endif() +endif() + +option(ODBC "enable MathProg ODBC support") +if(ODBC) + include(FindODBC) + if(ODBC_FOUND) + if(ODBC_CONFIG) + execute_process(COMMAND "${ODBC_CONFIG} --cflags" + RESULT_VARIABLE ODBC_RESULT + OUTPUT_VARIABLE ODBC_OUTPUT + ERROR_VARIABLE ODBC_ERROR) + if(ODBC_OUTPUT AND (NOT ODBC_ERROR)) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ODBC_OUTPUT}") + elseif(ODBC_ERROR) + message(FATAL_ERROR "'${ODBC_CONFIG} --cflags' returned ${ODBC_RESULT}: ${ODBC_ERROR}") + else() + message(FATAL_ERROR "'${ODBC_CONFIG} --cflags' produced no output") + endif() + else() + message(FATAL_ERROR "Could not run 'odbc-config --cflags' or 'iodbc-config --cflags'") + endif() + string(REGEX MATCH "/[^/\\]+$/gm" GMP_LIB_NAME "${GMP_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name + if (GMP_LIB_NAME) + add_compile_definitions(ODBC_DLNAME=${GMP_LIB_NAME}) + target_link_libraries(GLPK GMP_LIBRARIES) + target_include_directories(GLPK GMP_INCLUDE_DIRS) + else() + message(FATAL_ERROR "Could not determine ODBC/iODBC library name") + endif() + else() + message(FATAL_ERROR "ODBC/iODBC library not found") + endif() +endif() + +cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "SHARED_LIB" OFF) +if(MYSQL) + find_package(MySQL) + if(MYSQL_FOUND) + target_link_libraries(GLPK GMP_LIBRARIES) + target_include_directories(GLPK MYSQL_INCLUDE_DIRS) + else() + message(FATAL_ERROR "MySQL not found") + endif() +endif() + +option(IS_REENTRANT "enable reentrancy support" ON) +if(IS_REENTRANT) + if ( + (CMAKE_C_COMPILER_ID MATCHES "Clang") OR # matches AppleClang and Clang + (CMAKE_C_COMPILER_ID STREQUAL "GNU") OR + (CMAKE_C_COMPILER_ID STREQUAL "Intel") + ) + set(TLS "__thread") + elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") + set(TLS "__declspec(thread)") + else() + set(TLS "_Thread_local") # default to C11 standard, may break some builds if TLS isn't supported + endif() + add_compile_definitions(TLS=${TLS}) +endif() + option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) diff --git a/FindGMP.cmake b/FindGMP.cmake new file mode 100644 index 0000000..cad534f --- /dev/null +++ b/FindGMP.cmake @@ -0,0 +1,61 @@ +# Adapted from https://gist.github.com/RenatoUtsch/1623340 +# +# - Try to find GMP. +# Once done this will define: +# GMP_FOUND - If false, do not try to use GMP. +# GMP_INCLUDE_DIRS - Where to find GMP.h, etc. +# GMP_LIBRARIES - The libraries to link against. +# GMP_VERSION_STRING - Version in a string of GMP. +# +# Created by RenatoUtsch based on eAthena implementation. +# +# Please note that this module only supports Windows and Linux officially, but +# should work on all UNIX-like operational systems too. +# +#============================================================================= +# original gist (https://gist.github.com/RenatoUtsch/1623340) Copyright 2012 RenatoUtsch +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_library( GMP_LIBRARY + NAMES + "libgmp" + "libgmp-10" + "libgmp.so" + "libgmp.so.10" + "libgmp-10.so" + "libgmp.dll" + "libgmp-10.dll" + "libgmp.dylib" + "libgmp-10.dylib" + PATHS + "/lib" + "/lib64" + "/usr/lib" + "/usr/lib64" + "/usr/local/lib" + "/usr/local/lib64" + "C:\\Windows\\System32" + ) +if (GMP_LIBRARY) + set(GMP_INCLUDE_DIR include) +endif() + +# handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE if +# all listed variables are TRUE +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( GMP DEFAULT_MSG + REQUIRED_VARS GMP_LIBRARY GMP_INCLUDE_DIR ) + +set( GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR} ) +set( GMP_LIBRARIES ${GMP_LIBRARY} ) + +mark_as_advanced( GMP_INCLUDE_DIR GMP_LIBRARY ) diff --git a/FindMySQL.cmake b/FindMySQL.cmake new file mode 100644 index 0000000..4f68d69 --- /dev/null +++ b/FindMySQL.cmake @@ -0,0 +1,77 @@ +# https://gist.github.com/RenatoUtsch/1623340 +# - Try to find MySQL. +# Once done this will define: +# MYSQL_FOUND - If false, do not try to use MySQL. +# MYSQL_INCLUDE_DIRS - Where to find mysql.h, etc. +# MYSQL_LIBRARIES - The libraries to link against. +# MYSQL_VERSION_STRING - Version in a string of MySQL. +# +# Created by RenatoUtsch based on eAthena implementation. +# +# Please note that this module only supports Windows and Linux officially, but +# should work on all UNIX-like operational systems too. +# +#============================================================================= +# Copyright 2012 RenatoUtsch +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) +if( WIN32 ) + find_path( MYSQL_INCLUDE_DIR + NAMES "mysql.h" + PATHS "$ENV{PROGRAMFILES}/MySQL/*/include" + "$ENV{PROGRAMFILES(x86)}/MySQL/*/include" + "$ENV{SYSTEMDRIVE}/MySQL/*/include" ) + + find_library( MYSQL_LIBRARY + NAMES "mysqlclient" "mysqlclient_r" + PATHS "$ENV{PROGRAMFILES}/MySQL/*/lib" + "$ENV{PROGRAMFILES(x86)}/MySQL/*/lib" + "$ENV{SYSTEMDRIVE}/MySQL/*/lib" ) +else() + find_path( MYSQL_INCLUDE_DIR + NAMES "mysql.h" + PATHS "/usr/include/mysql" + "/usr/local/include/mysql" + "/usr/mysql/include/mysql" ) + + find_library( MYSQL_LIBRARY + NAMES "mysqlclient" "mysqlclient_r" + PATHS "/lib/mysql" + "/lib64/mysql" + "/usr/lib/mysql" + "/usr/lib64/mysql" + "/usr/local/lib/mysql" + "/usr/local/lib64/mysql" + "/usr/mysql/lib/mysql" + "/usr/mysql/lib64/mysql" ) +endif() + + + +if( MYSQL_INCLUDE_DIR AND EXISTS "${MYSQL_INCLUDE_DIRS}/mysql_version.h" ) + file( STRINGS "${MYSQL_INCLUDE_DIRS}/mysql_version.h" + MYSQL_VERSION_H REGEX "^#define[ \t]+MYSQL_SERVER_VERSION[ \t]+\"[^\"]+\".*$" ) + string( REGEX REPLACE + "^.*MYSQL_SERVER_VERSION[ \t]+\"([^\"]+)\".*$" "\\1" MYSQL_VERSION_STRING + "${MYSQL_VERSION_H}" ) +endif() + +# handle the QUIETLY and REQUIRED arguments and set MYSQL_FOUND to TRUE if +# all listed variables are TRUE +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( MYSQL DEFAULT_MSG + REQUIRED_VARS MYSQL_LIBRARY MYSQL_INCLUDE_DIR + VERSION_VAR MYSQL_VERSION_STRING ) + +set( MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDE_DIR} ) +set( MYSQL_LIBRARIES ${MYSQL_LIBRARY} ) + +mark_as_advanced( MYSQL_INCLUDE_DIR MYSQL_LIBRARY ) From 7c6d0530bf3f52a7b37a3b808212bb8e5e17f6ae Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:02:00 +0200 Subject: [PATCH 02/51] Added checks and includes for system libs, functions and headers --- src/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 33dc226..6dee9a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,6 +42,36 @@ target_link_libraries(GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) +# check system libs functions and headers +# m::exp +check_symbol_exists(exp "math.h" HAVE_EXP) +if(NOT HAVE_EXP) + unset(HAVE_EXP CACHE) + list(APPEND CMAKE_REQUIRED_LIBRARIES "m") + check_symbol_exists(exp "math.h" HAVE_EXP) + if(HAVE_EXP) + target_link_libraries(GLPK PRIVATE m) + else() + message(FATAL_ERROR "exp function not found") + endif() +endif() + +# sys/time.h +check_include_file(sys/time.h HAS_TIME_H) +if(HAS_TIME_H) + add_compile_definitions(HAVE_SYS_TIME_H=1) +else() + add_compile_definitions(HAVE_SYS_TIME_H=N/A) +endif() + +# gettimeofday function +check_function_exists(gettimeofday, HAVE_GETTIMEOFDAY_FUNC) +if(HAVE_GETTIMEOFDAY_FUNC) + add_compile_definitions(HAVE_GETTIMEOFDAY=1) +else() + add_compile_definitions(HAVE_GETTIMEOFDAY=N/A) +endif() + #add_subdirectory(tests) # Install From 04d7e16c134e4474c9328ac8af63abbb771be989 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:03:42 +0200 Subject: [PATCH 03/51] gitignore CLion IDE files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3641db3..ae564bb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ cache/ # IDE .vs/ .cache/ +.idea/ # Kdevelop .kdev4/ *.kdev4 From 67bcbfc0259f26f90f13f91856ed0c25ef24f1e6 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:28:45 +0200 Subject: [PATCH 04/51] fixed missing CMake includes --- CMakeLists.txt | 1 + src/CMakeLists.txt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfcdc95..b1d34ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ if(ODBC) endif() endif() +include(CMakeDependentOption) cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "SHARED_LIB" OFF) if(MYSQL) find_package(MySQL) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6dee9a2..66a109f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,7 @@ add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) # check system libs functions and headers # m::exp +include(CheckSymbolExists) check_symbol_exists(exp "math.h" HAVE_EXP) if(NOT HAVE_EXP) unset(HAVE_EXP CACHE) @@ -57,6 +58,7 @@ if(NOT HAVE_EXP) endif() # sys/time.h +include(CheckIncludeFile) check_include_file(sys/time.h HAS_TIME_H) if(HAS_TIME_H) add_compile_definitions(HAVE_SYS_TIME_H=1) @@ -65,6 +67,7 @@ else() endif() # gettimeofday function +include(CheckFunctionExists) check_function_exists(gettimeofday, HAVE_GETTIMEOFDAY_FUNC) if(HAVE_GETTIMEOFDAY_FUNC) add_compile_definitions(HAVE_GETTIMEOFDAY=1) From ebc2f7e31b70398949801672a914bf839192f46d Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:41:04 +0200 Subject: [PATCH 05/51] fixed compile definitions --- src/CMakeLists.txt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66a109f..a80c08d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,12 +58,12 @@ if(NOT HAVE_EXP) endif() # sys/time.h -include(CheckIncludeFile) -check_include_file(sys/time.h HAS_TIME_H) -if(HAS_TIME_H) - add_compile_definitions(HAVE_SYS_TIME_H=1) -else() - add_compile_definitions(HAVE_SYS_TIME_H=N/A) +if(NOT MSVC) + include(CheckIncludeFile) + check_include_file(sys/time.h HAS_TIME_H) + if(HAS_TIME_H) + add_compile_definitions(HAVE_SYS_TIME_H=1) + endif() endif() # gettimeofday function @@ -71,8 +71,6 @@ include(CheckFunctionExists) check_function_exists(gettimeofday, HAVE_GETTIMEOFDAY_FUNC) if(HAVE_GETTIMEOFDAY_FUNC) add_compile_definitions(HAVE_GETTIMEOFDAY=1) -else() - add_compile_definitions(HAVE_GETTIMEOFDAY=N/A) endif() #add_subdirectory(tests) From 8865447702ed1c105d4e57d28749c53b9f462fdc Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 09:41:31 +0200 Subject: [PATCH 06/51] added missing gmp.h --- include/gmp.h | 2337 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2337 insertions(+) create mode 100644 include/gmp.h diff --git a/include/gmp.h b/include/gmp.h new file mode 100644 index 0000000..a46d01b --- /dev/null +++ b/include/gmp.h @@ -0,0 +1,2337 @@ +//Windows typically doesn't have GMP.h on its PATH, so I've included it here +/* Definitions for GNU multiple precision functions. -*- mode: c -*- + +Copyright 1991, 1993-1997, 1999-2016, 2020 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + +or + + * the GNU General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any + later version. + +or both in parallel, as here. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received copies of the GNU General Public License and the +GNU Lesser General Public License along with the GNU MP Library. If not, +see https://www.gnu.org/licenses/. */ + +#ifndef __GMP_H__ + +#if defined (__cplusplus) +#include /* for std::istream, std::ostream, std::string */ +#include +#endif + + +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#define __GMP_HAVE_HOST_CPU_FAMILY_power 0 +#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0 +#define GMP_LIMB_BITS 64 +#define GMP_NAIL_BITS 0 +#endif +#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) +#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS) +#define GMP_NUMB_MAX GMP_NUMB_MASK +#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) + + +#ifndef __GNU_MP__ +#define __GNU_MP__ 6 + +#include /* for size_t */ +#include + +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +/* #undef _LONG_LONG_LIMB */ +#define __GMP_LIBGMP_DLL 0 +#endif + + +/* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in + all other circumstances. + + When compiling objects for libgmp, __GMP_DECLSPEC is an export directive, + or when compiling for an application it's an import directive. The two + cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles + (and not defined from an application). + + __GMP_DECLSPEC_XX is similarly used for libgmpxx. __GMP_WITHIN_GMPXX + indicates when building libgmpxx, and in that case libgmpxx functions are + exports, but libgmp functions which might get called are imports. + + Libtool DLL_EXPORT define is not used. + + There's no attempt to support GMP built both static and DLL. Doing so + would mean applications would have to tell us which of the two is going + to be used when linking, and that seems very tedious and error prone if + using GMP by hand, and equally tedious from a package since autoconf and + automake don't give much help. + + __GMP_DECLSPEC is required on all documented global functions and + variables, the various internals in gmp-impl.h etc can be left unadorned. + But internals used by the test programs or speed measuring programs + should have __GMP_DECLSPEC, and certainly constants or variables must + have it or the wrong address will be resolved. + + In gcc __declspec can go at either the start or end of a prototype. + + In Microsoft C __declspec must go at the start, or after the type like + void __declspec(...) *foo()". There's no __dllexport or anything to + guard against someone foolish #defining dllexport. _export used to be + available, but no longer. + + In Borland C _export still exists, but needs to go after the type, like + "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to + make use of that. Probably more trouble than it's worth. */ + +#if defined (__GNUC__) +#define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__) +#define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__) +#endif +#if defined (_MSC_VER) || defined (__BORLANDC__) +#define __GMP_DECLSPEC_EXPORT __declspec(dllexport) +#define __GMP_DECLSPEC_IMPORT __declspec(dllimport) +#endif +#ifdef __WATCOMC__ +#define __GMP_DECLSPEC_EXPORT __export +#define __GMP_DECLSPEC_IMPORT __import +#endif +#ifdef __IBMC__ +#define __GMP_DECLSPEC_EXPORT _Export +#define __GMP_DECLSPEC_IMPORT _Import +#endif + +#if __GMP_LIBGMP_DLL +#ifdef __GMP_WITHIN_GMP +/* compiling to go into a DLL libgmp */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into an application which will link to a DLL libgmp */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC +#endif + + +#ifdef __GMP_SHORT_LIMB +typedef unsigned int mp_limb_t; +typedef int mp_limb_signed_t; +#else +#ifdef _LONG_LONG_LIMB +typedef unsigned long long int mp_limb_t; +typedef long long int mp_limb_signed_t; +#else +typedef unsigned long int mp_limb_t; +typedef long int mp_limb_signed_t; +#endif +#endif +typedef unsigned long int mp_bitcnt_t; + +/* For reference, note that the name __mpz_struct gets into C++ mangled + function names, which means although the "__" suggests an internal, we + must leave this name for binary compatibility. */ +typedef struct +{ + int _mp_alloc; /* Number of *limbs* allocated and pointed + to by the _mp_d field. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpz_struct; + +#endif /* __GNU_MP__ */ + + +typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */ +typedef __mpz_struct mpz_t[1]; + +typedef mp_limb_t * mp_ptr; +typedef const mp_limb_t * mp_srcptr; +#if defined (_CRAY) && ! defined (_CRAYMPP) +/* plain `int' is much faster (48 bits) */ +#define __GMP_MP_SIZE_T_INT 1 +typedef int mp_size_t; +typedef int mp_exp_t; +#else +#define __GMP_MP_SIZE_T_INT 0 +typedef long int mp_size_t; +typedef long int mp_exp_t; +#endif + +typedef struct +{ + __mpz_struct _mp_num; + __mpz_struct _mp_den; +} __mpq_struct; + +typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */ +typedef __mpq_struct mpq_t[1]; + +typedef struct +{ + int _mp_prec; /* Max precision, in number of `mp_limb_t's. + Set by mpf_init and modified by + mpf_set_prec. The area pointed to by the + _mp_d field contains `prec' + 1 limbs. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpf_struct; + +/* typedef __mpf_struct MP_FLOAT; */ +typedef __mpf_struct mpf_t[1]; + +/* Available random number generation algorithms. */ +typedef enum +{ + GMP_RAND_ALG_DEFAULT = 0, + GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ +} gmp_randalg_t; + +/* Random state struct. */ +typedef struct +{ + mpz_t _mp_seed; /* _mp_d member points to state of the generator. */ + gmp_randalg_t _mp_alg; /* Currently unused. */ + union { + void *_mp_lc; /* Pointer to function pointers structure. */ + } _mp_algdata; +} __gmp_randstate_struct; +typedef __gmp_randstate_struct gmp_randstate_t[1]; + +/* Types for function declarations in gmp files. */ +/* ??? Should not pollute user name space with these ??? */ +typedef const __mpz_struct *mpz_srcptr; +typedef __mpz_struct *mpz_ptr; +typedef const __mpf_struct *mpf_srcptr; +typedef __mpf_struct *mpf_ptr; +typedef const __mpq_struct *mpq_srcptr; +typedef __mpq_struct *mpq_ptr; + + +#if __GMP_LIBGMP_DLL +#ifdef __GMP_WITHIN_GMPXX +/* compiling to go into a DLL libgmpxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into a application which will link to a DLL libgmpxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC_XX +#endif + + +#ifndef __MPN +#define __MPN(x) __gmpn_##x +#endif + +/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, + defines EOF but not FILE. */ +#if defined (FILE) \ + || defined (H_STDIO) \ + || defined (_H_STDIO) /* AIX */ \ + || defined (_STDIO_H) /* glibc, Sun, SCO */ \ + || defined (_STDIO_H_) /* BSD, OSF */ \ + || defined (__STDIO_H) /* Borland */ \ + || defined (__STDIO_H__) /* IRIX */ \ + || defined (_STDIO_INCLUDED) /* HPUX */ \ + || defined (__dj_include_stdio_h_) /* DJGPP */ \ + || defined (_FILE_DEFINED) /* Microsoft */ \ + || defined (__STDIO__) /* Apple MPW MrC */ \ + || defined (_MSL_STDIO_H) /* Metrowerks */ \ + || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ + || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \ + || defined (__STDIO_LOADED) /* VMS */ \ + || defined (__DEFINED_FILE) /* musl */ +#define _GMP_H_HAVE_FILE 1 +#endif + +/* In ISO C, if a prototype involving "struct obstack *" is given without + that structure defined, then the struct is scoped down to just the + prototype, causing a conflict if it's subsequently defined for real. So + only give prototypes if we've got obstack.h. */ +#if defined (_OBSTACK_H) /* glibc */ +#define _GMP_H_HAVE_OBSTACK 1 +#endif + +/* The prototypes for gmp_vprintf etc are provided only if va_list is defined, + via an application having included . Usually va_list is a typedef + so can't be tested directly, but C99 specifies that va_start is a macro. + + will define some sort of va_list for vprintf and vfprintf, but + let's not bother trying to use that since it's not standard and since + application uses for gmp_vprintf etc will almost certainly require the + whole anyway. */ + +#ifdef va_start +#define _GMP_H_HAVE_VA_LIST 1 +#endif + +/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */ +#if defined (__GNUC__) && defined (__GNUC_MINOR__) +#define __GMP_GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GMP_GNUC_PREREQ(maj, min) 0 +#endif + +/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically + it means a function does nothing but examine its arguments and memory + (global or via arguments) to generate a return value, but changes nothing + and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets + tune/common.c etc turn this off when trying to write timing loops. */ +#if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE) +#define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +#define __GMP_ATTRIBUTE_PURE +#endif + + +/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean + to "g++ -Wold-style-cast". + + Casts in "extern inline" code within an extern "C" block don't induce + these warnings, so __GMP_CAST only needs to be used on documented + macros. */ + +#ifdef __cplusplus +#define __GMP_CAST(type, expr) (static_cast (expr)) +#else +#define __GMP_CAST(type, expr) ((type) (expr)) +#endif + + +/* An empty "throw ()" means the function doesn't throw any C++ exceptions, + this can save some stack frame info in applications. + + Currently it's given only on functions which never divide-by-zero etc, + don't allocate memory, and are expected to never need to allocate memory. + This leaves open the possibility of a C++ throw from a future GMP + exceptions scheme. + + mpz_set_ui etc are omitted to leave open the lazy allocation scheme + described in doc/tasks.html. mpz_get_d etc are omitted to leave open + exceptions for float overflows. + + Note that __GMP_NOTHROW must be given on any inlines the same as on their + prototypes (for g++ at least, where they're used together). Note also + that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like + __GMP_ATTRIBUTE_PURE. */ + +#if defined (__cplusplus) +#if __cplusplus >= 201103L +#define __GMP_NOTHROW noexcept +#else +#define __GMP_NOTHROW throw () +#endif +#else +#define __GMP_NOTHROW +#endif + + +/* PORTME: What other compilers have a useful "extern inline"? "static + inline" would be an acceptable substitute if the compiler (or linker) + discards unused statics. */ + + /* gcc has __inline__ in all modes, including strict ansi. Give a prototype + for an inline too, so as to correctly specify "dllimport" on windows, in + case the function is called rather than inlined. + GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. */ +#ifdef __GNUC__ +#if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2) \ + || (defined __GNUC_GNU_INLINE__ && defined __cplusplus) +#define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__)) +#else +#define __GMP_EXTERN_INLINE extern __inline__ +#endif +#define __GMP_INLINE_PROTOTYPES 1 +#endif + +/* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1 + strict ANSI mode. Inlining is done even when not optimizing (ie. -O0 + mode, which is the default), but an unnecessary local copy of foo is + emitted unless -O is used. "extern __inline" is accepted, but the + "extern" appears to be ignored, ie. it becomes a plain global function + but which is inlined within its file. Don't know if all old versions of + DEC C supported __inline, but as a start let's do the right thing for + current versions. */ +#ifdef __DECC +#define __GMP_EXTERN_INLINE static __inline +#endif + +/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict + ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes + place under -O. Without -O "foo" seems to be emitted whether it's used + or not, which is wasteful. "extern inline foo()" isn't useful, the + "extern" is apparently ignored, so foo is inlined if possible but also + emitted as a global, which causes multiple definition errors when + building a shared libgmp. */ +#ifdef __SCO_VERSION__ +#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE static inline +#endif +#endif + +/* Microsoft's C compiler accepts __inline */ +#ifdef _MSC_VER +#define __GMP_EXTERN_INLINE __inline +#endif + +/* Recent enough Sun C compilers want "inline" */ +#if defined (__SUNPRO_C) && __SUNPRO_C >= 0x560 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE inline +#endif + +/* Somewhat older Sun C compilers want "static inline" */ +#if defined (__SUNPRO_C) && __SUNPRO_C >= 0x540 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE static inline +#endif + + +/* C++ always has "inline" and since it's a normal feature the linker should + discard duplicate non-inlined copies, or if it doesn't then that's a + problem for everyone, not just GMP. */ +#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE inline +#endif + +/* Don't do any inlining within a configure run, since if the compiler ends + up emitting copies of the code into the object file it can end up + demanding the various support routines (like mpn_popcount) for linking, + making the "alloca" test and perhaps others fail. And on hppa ia64 a + pre-release gcc 3.2 was seen not respecting the "extern" in "extern + __inline__", triggering this problem too. */ +#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE +#undef __GMP_EXTERN_INLINE +#endif + +/* By default, don't give a prototype when there's going to be an inline + version. Note in particular that Cray C++ objects to the combination of + prototype and inline. */ +#ifdef __GMP_EXTERN_INLINE +#ifndef __GMP_INLINE_PROTOTYPES +#define __GMP_INLINE_PROTOTYPES 0 +#endif +#else +#define __GMP_INLINE_PROTOTYPES 1 +#endif + + +#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x)) +#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i)) + + +/* __builtin_expect is in gcc 3.0, and not in 2.95. */ +#if __GMP_GNUC_PREREQ (3,0) +#define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1) +#define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0) +#else +#define __GMP_LIKELY(cond) (cond) +#define __GMP_UNLIKELY(cond) (cond) +#endif + +#ifdef _CRAY +#define __GMP_CRAY_Pragma(str) _Pragma (str) +#else +#define __GMP_CRAY_Pragma(str) +#endif + + +/* Allow direct user access to numerator and denominator of an mpq_t object. */ +#define mpq_numref(Q) (&((Q)->_mp_num)) +#define mpq_denref(Q) (&((Q)->_mp_den)) + + +#if defined (__cplusplus) +extern "C" { +using std::FILE; +#endif + +#define mp_set_memory_functions __gmp_set_memory_functions +__GMP_DECLSPEC void mp_set_memory_functions (void *(*) (size_t), + void *(*) (void *, size_t, size_t), + void (*) (void *, size_t)) __GMP_NOTHROW; + +#define mp_get_memory_functions __gmp_get_memory_functions +__GMP_DECLSPEC void mp_get_memory_functions (void *(**) (size_t), + void *(**) (void *, size_t, size_t), + void (**) (void *, size_t)) __GMP_NOTHROW; + +#define mp_bits_per_limb __gmp_bits_per_limb +__GMP_DECLSPEC extern const int mp_bits_per_limb; + +#define gmp_errno __gmp_errno +__GMP_DECLSPEC extern int gmp_errno; + +#define gmp_version __gmp_version +__GMP_DECLSPEC extern const char * const gmp_version; + + +/**************** Random number routines. ****************/ + +/* obsolete */ +#define gmp_randinit __gmp_randinit +__GMP_DECLSPEC void gmp_randinit (gmp_randstate_t, gmp_randalg_t, ...); + +#define gmp_randinit_default __gmp_randinit_default +__GMP_DECLSPEC void gmp_randinit_default (gmp_randstate_t); + +#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp +__GMP_DECLSPEC void gmp_randinit_lc_2exp (gmp_randstate_t, mpz_srcptr, unsigned long int, mp_bitcnt_t); + +#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size +__GMP_DECLSPEC int gmp_randinit_lc_2exp_size (gmp_randstate_t, mp_bitcnt_t); + +#define gmp_randinit_mt __gmp_randinit_mt +__GMP_DECLSPEC void gmp_randinit_mt (gmp_randstate_t); + +#define gmp_randinit_set __gmp_randinit_set +__GMP_DECLSPEC void gmp_randinit_set (gmp_randstate_t, const __gmp_randstate_struct *); + +#define gmp_randseed __gmp_randseed +__GMP_DECLSPEC void gmp_randseed (gmp_randstate_t, mpz_srcptr); + +#define gmp_randseed_ui __gmp_randseed_ui +__GMP_DECLSPEC void gmp_randseed_ui (gmp_randstate_t, unsigned long int); + +#define gmp_randclear __gmp_randclear +__GMP_DECLSPEC void gmp_randclear (gmp_randstate_t); + +#define gmp_urandomb_ui __gmp_urandomb_ui +__GMP_DECLSPEC unsigned long gmp_urandomb_ui (gmp_randstate_t, unsigned long); + +#define gmp_urandomm_ui __gmp_urandomm_ui +__GMP_DECLSPEC unsigned long gmp_urandomm_ui (gmp_randstate_t, unsigned long); + + +/**************** Formatted output routines. ****************/ + +#define gmp_asprintf __gmp_asprintf +__GMP_DECLSPEC int gmp_asprintf (char **, const char *, ...); + +#define gmp_fprintf __gmp_fprintf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fprintf (FILE *, const char *, ...); +#endif + +#define gmp_obstack_printf __gmp_obstack_printf +#if defined (_GMP_H_HAVE_OBSTACK) +__GMP_DECLSPEC int gmp_obstack_printf (struct obstack *, const char *, ...); +#endif + +#define gmp_obstack_vprintf __gmp_obstack_vprintf +#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_obstack_vprintf (struct obstack *, const char *, va_list); +#endif + +#define gmp_printf __gmp_printf +__GMP_DECLSPEC int gmp_printf (const char *, ...); + +#define gmp_snprintf __gmp_snprintf +__GMP_DECLSPEC int gmp_snprintf (char *, size_t, const char *, ...); + +#define gmp_sprintf __gmp_sprintf +__GMP_DECLSPEC int gmp_sprintf (char *, const char *, ...); + +#define gmp_vasprintf __gmp_vasprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vasprintf (char **, const char *, va_list); +#endif + +#define gmp_vfprintf __gmp_vfprintf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfprintf (FILE *, const char *, va_list); +#endif + +#define gmp_vprintf __gmp_vprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vprintf (const char *, va_list); +#endif + +#define gmp_vsnprintf __gmp_vsnprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsnprintf (char *, size_t, const char *, va_list); +#endif + +#define gmp_vsprintf __gmp_vsprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsprintf (char *, const char *, va_list); +#endif + + +/**************** Formatted input routines. ****************/ + +#define gmp_fscanf __gmp_fscanf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fscanf (FILE *, const char *, ...); +#endif + +#define gmp_scanf __gmp_scanf +__GMP_DECLSPEC int gmp_scanf (const char *, ...); + +#define gmp_sscanf __gmp_sscanf +__GMP_DECLSPEC int gmp_sscanf (const char *, const char *, ...); + +#define gmp_vfscanf __gmp_vfscanf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfscanf (FILE *, const char *, va_list); +#endif + +#define gmp_vscanf __gmp_vscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vscanf (const char *, va_list); +#endif + +#define gmp_vsscanf __gmp_vsscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsscanf (const char *, const char *, va_list); +#endif + + +/**************** Integer (i.e. Z) routines. ****************/ + +#define _mpz_realloc __gmpz_realloc +#define mpz_realloc __gmpz_realloc +__GMP_DECLSPEC void *_mpz_realloc (mpz_ptr, mp_size_t); + +#define mpz_abs __gmpz_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs) +__GMP_DECLSPEC void mpz_abs (mpz_ptr, mpz_srcptr); +#endif + +#define mpz_add __gmpz_add +__GMP_DECLSPEC void mpz_add (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_add_ui __gmpz_add_ui +__GMP_DECLSPEC void mpz_add_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_addmul __gmpz_addmul +__GMP_DECLSPEC void mpz_addmul (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_addmul_ui __gmpz_addmul_ui +__GMP_DECLSPEC void mpz_addmul_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_and __gmpz_and +__GMP_DECLSPEC void mpz_and (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_array_init __gmpz_array_init +__GMP_DECLSPEC void mpz_array_init (mpz_ptr, mp_size_t, mp_size_t); + +#define mpz_bin_ui __gmpz_bin_ui +__GMP_DECLSPEC void mpz_bin_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_bin_uiui __gmpz_bin_uiui +__GMP_DECLSPEC void mpz_bin_uiui (mpz_ptr, unsigned long int, unsigned long int); + +#define mpz_cdiv_q __gmpz_cdiv_q +__GMP_DECLSPEC void mpz_cdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp +__GMP_DECLSPEC void mpz_cdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_cdiv_qr __gmpz_cdiv_qr +__GMP_DECLSPEC void mpz_cdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_cdiv_r __gmpz_cdiv_r +__GMP_DECLSPEC void mpz_cdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp +__GMP_DECLSPEC void mpz_cdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_cdiv_ui __gmpz_cdiv_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; + +#define mpz_clear __gmpz_clear +__GMP_DECLSPEC void mpz_clear (mpz_ptr); + +#define mpz_clears __gmpz_clears +__GMP_DECLSPEC void mpz_clears (mpz_ptr, ...); + +#define mpz_clrbit __gmpz_clrbit +__GMP_DECLSPEC void mpz_clrbit (mpz_ptr, mp_bitcnt_t); + +#define mpz_cmp __gmpz_cmp +__GMP_DECLSPEC int mpz_cmp (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmp_d __gmpz_cmp_d +__GMP_DECLSPEC int mpz_cmp_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE; + +#define _mpz_cmp_si __gmpz_cmp_si +__GMP_DECLSPEC int _mpz_cmp_si (mpz_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define _mpz_cmp_ui __gmpz_cmp_ui +__GMP_DECLSPEC int _mpz_cmp_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs __gmpz_cmpabs +__GMP_DECLSPEC int mpz_cmpabs (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs_d __gmpz_cmpabs_d +__GMP_DECLSPEC int mpz_cmpabs_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs_ui __gmpz_cmpabs_ui +__GMP_DECLSPEC int mpz_cmpabs_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_com __gmpz_com +__GMP_DECLSPEC void mpz_com (mpz_ptr, mpz_srcptr); + +#define mpz_combit __gmpz_combit +__GMP_DECLSPEC void mpz_combit (mpz_ptr, mp_bitcnt_t); + +#define mpz_congruent_p __gmpz_congruent_p +__GMP_DECLSPEC int mpz_congruent_p (mpz_srcptr, mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p +__GMP_DECLSPEC int mpz_congruent_2exp_p (mpz_srcptr, mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_congruent_ui_p __gmpz_congruent_ui_p +__GMP_DECLSPEC int mpz_congruent_ui_p (mpz_srcptr, unsigned long, unsigned long) __GMP_ATTRIBUTE_PURE; + +#define mpz_divexact __gmpz_divexact +__GMP_DECLSPEC void mpz_divexact (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_divexact_ui __gmpz_divexact_ui +__GMP_DECLSPEC void mpz_divexact_ui (mpz_ptr, mpz_srcptr, unsigned long); + +#define mpz_divisible_p __gmpz_divisible_p +__GMP_DECLSPEC int mpz_divisible_p (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_divisible_ui_p __gmpz_divisible_ui_p +__GMP_DECLSPEC int mpz_divisible_ui_p (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE; + +#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p +__GMP_DECLSPEC int mpz_divisible_2exp_p (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_dump __gmpz_dump +__GMP_DECLSPEC void mpz_dump (mpz_srcptr); + +#define mpz_export __gmpz_export +__GMP_DECLSPEC void *mpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr); + +#define mpz_fac_ui __gmpz_fac_ui +__GMP_DECLSPEC void mpz_fac_ui (mpz_ptr, unsigned long int); + +#define mpz_2fac_ui __gmpz_2fac_ui +__GMP_DECLSPEC void mpz_2fac_ui (mpz_ptr, unsigned long int); + +#define mpz_mfac_uiui __gmpz_mfac_uiui +__GMP_DECLSPEC void mpz_mfac_uiui (mpz_ptr, unsigned long int, unsigned long int); + +#define mpz_primorial_ui __gmpz_primorial_ui +__GMP_DECLSPEC void mpz_primorial_ui (mpz_ptr, unsigned long int); + +#define mpz_fdiv_q __gmpz_fdiv_q +__GMP_DECLSPEC void mpz_fdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp +__GMP_DECLSPEC void mpz_fdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_fdiv_qr __gmpz_fdiv_qr +__GMP_DECLSPEC void mpz_fdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_fdiv_r __gmpz_fdiv_r +__GMP_DECLSPEC void mpz_fdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp +__GMP_DECLSPEC void mpz_fdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_fdiv_ui __gmpz_fdiv_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; + +#define mpz_fib_ui __gmpz_fib_ui +__GMP_DECLSPEC void mpz_fib_ui (mpz_ptr, unsigned long int); + +#define mpz_fib2_ui __gmpz_fib2_ui +__GMP_DECLSPEC void mpz_fib2_ui (mpz_ptr, mpz_ptr, unsigned long int); + +#define mpz_fits_sint_p __gmpz_fits_sint_p +__GMP_DECLSPEC int mpz_fits_sint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_slong_p __gmpz_fits_slong_p +__GMP_DECLSPEC int mpz_fits_slong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_sshort_p __gmpz_fits_sshort_p +__GMP_DECLSPEC int mpz_fits_sshort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_uint_p __gmpz_fits_uint_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_DECLSPEC int mpz_fits_uint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_fits_ulong_p __gmpz_fits_ulong_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_DECLSPEC int mpz_fits_ulong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_fits_ushort_p __gmpz_fits_ushort_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_DECLSPEC int mpz_fits_ushort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_gcd __gmpz_gcd +__GMP_DECLSPEC void mpz_gcd (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_gcd_ui __gmpz_gcd_ui +__GMP_DECLSPEC unsigned long int mpz_gcd_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_gcdext __gmpz_gcdext +__GMP_DECLSPEC void mpz_gcdext (mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_get_d __gmpz_get_d +__GMP_DECLSPEC double mpz_get_d (mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_get_d_2exp __gmpz_get_d_2exp +__GMP_DECLSPEC double mpz_get_d_2exp (signed long int *, mpz_srcptr); + +#define mpz_get_si __gmpz_get_si +__GMP_DECLSPEC /* signed */ long int mpz_get_si (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_get_str __gmpz_get_str +__GMP_DECLSPEC char *mpz_get_str (char *, int, mpz_srcptr); + +#define mpz_get_ui __gmpz_get_ui +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui) +__GMP_DECLSPEC unsigned long int mpz_get_ui (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_getlimbn __gmpz_getlimbn +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn) +__GMP_DECLSPEC mp_limb_t mpz_getlimbn (mpz_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_hamdist __gmpz_hamdist +__GMP_DECLSPEC mp_bitcnt_t mpz_hamdist (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_import __gmpz_import +__GMP_DECLSPEC void mpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *); + +#define mpz_init __gmpz_init +__GMP_DECLSPEC void mpz_init (mpz_ptr) __GMP_NOTHROW; + +#define mpz_init2 __gmpz_init2 +__GMP_DECLSPEC void mpz_init2 (mpz_ptr, mp_bitcnt_t); + +#define mpz_inits __gmpz_inits +__GMP_DECLSPEC void mpz_inits (mpz_ptr, ...) __GMP_NOTHROW; + +#define mpz_init_set __gmpz_init_set +__GMP_DECLSPEC void mpz_init_set (mpz_ptr, mpz_srcptr); + +#define mpz_init_set_d __gmpz_init_set_d +__GMP_DECLSPEC void mpz_init_set_d (mpz_ptr, double); + +#define mpz_init_set_si __gmpz_init_set_si +__GMP_DECLSPEC void mpz_init_set_si (mpz_ptr, signed long int); + +#define mpz_init_set_str __gmpz_init_set_str +__GMP_DECLSPEC int mpz_init_set_str (mpz_ptr, const char *, int); + +#define mpz_init_set_ui __gmpz_init_set_ui +__GMP_DECLSPEC void mpz_init_set_ui (mpz_ptr, unsigned long int); + +#define mpz_inp_raw __gmpz_inp_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_raw (mpz_ptr, FILE *); +#endif + +#define mpz_inp_str __gmpz_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_str (mpz_ptr, FILE *, int); +#endif + +#define mpz_invert __gmpz_invert +__GMP_DECLSPEC int mpz_invert (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_ior __gmpz_ior +__GMP_DECLSPEC void mpz_ior (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_jacobi __gmpz_jacobi +__GMP_DECLSPEC int mpz_jacobi (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_kronecker mpz_jacobi /* alias */ + +#define mpz_kronecker_si __gmpz_kronecker_si +__GMP_DECLSPEC int mpz_kronecker_si (mpz_srcptr, long) __GMP_ATTRIBUTE_PURE; + +#define mpz_kronecker_ui __gmpz_kronecker_ui +__GMP_DECLSPEC int mpz_kronecker_ui (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE; + +#define mpz_si_kronecker __gmpz_si_kronecker +__GMP_DECLSPEC int mpz_si_kronecker (long, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_ui_kronecker __gmpz_ui_kronecker +__GMP_DECLSPEC int mpz_ui_kronecker (unsigned long, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_lcm __gmpz_lcm +__GMP_DECLSPEC void mpz_lcm (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_lcm_ui __gmpz_lcm_ui +__GMP_DECLSPEC void mpz_lcm_ui (mpz_ptr, mpz_srcptr, unsigned long); + +#define mpz_legendre mpz_jacobi /* alias */ + +#define mpz_lucnum_ui __gmpz_lucnum_ui +__GMP_DECLSPEC void mpz_lucnum_ui (mpz_ptr, unsigned long int); + +#define mpz_lucnum2_ui __gmpz_lucnum2_ui +__GMP_DECLSPEC void mpz_lucnum2_ui (mpz_ptr, mpz_ptr, unsigned long int); + +#define mpz_millerrabin __gmpz_millerrabin +__GMP_DECLSPEC int mpz_millerrabin (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE; + +#define mpz_mod __gmpz_mod +__GMP_DECLSPEC void mpz_mod (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */ + +#define mpz_mul __gmpz_mul +__GMP_DECLSPEC void mpz_mul (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_mul_2exp __gmpz_mul_2exp +__GMP_DECLSPEC void mpz_mul_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_mul_si __gmpz_mul_si +__GMP_DECLSPEC void mpz_mul_si (mpz_ptr, mpz_srcptr, long int); + +#define mpz_mul_ui __gmpz_mul_ui +__GMP_DECLSPEC void mpz_mul_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_neg __gmpz_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg) +__GMP_DECLSPEC void mpz_neg (mpz_ptr, mpz_srcptr); +#endif + +#define mpz_nextprime __gmpz_nextprime +__GMP_DECLSPEC void mpz_nextprime (mpz_ptr, mpz_srcptr); + +#define mpz_out_raw __gmpz_out_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_raw (FILE *, mpz_srcptr); +#endif + +#define mpz_out_str __gmpz_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_str (FILE *, int, mpz_srcptr); +#endif + +#define mpz_perfect_power_p __gmpz_perfect_power_p +__GMP_DECLSPEC int mpz_perfect_power_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpz_perfect_square_p __gmpz_perfect_square_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_DECLSPEC int mpz_perfect_square_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_popcount __gmpz_popcount +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount) +__GMP_DECLSPEC mp_bitcnt_t mpz_popcount (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_pow_ui __gmpz_pow_ui +__GMP_DECLSPEC void mpz_pow_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_powm __gmpz_powm +__GMP_DECLSPEC void mpz_powm (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr); + +#define mpz_powm_sec __gmpz_powm_sec +__GMP_DECLSPEC void mpz_powm_sec (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr); + +#define mpz_powm_ui __gmpz_powm_ui +__GMP_DECLSPEC void mpz_powm_ui (mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr); + +#define mpz_probab_prime_p __gmpz_probab_prime_p +__GMP_DECLSPEC int mpz_probab_prime_p (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE; + +#define mpz_random __gmpz_random +__GMP_DECLSPEC void mpz_random (mpz_ptr, mp_size_t); + +#define mpz_random2 __gmpz_random2 +__GMP_DECLSPEC void mpz_random2 (mpz_ptr, mp_size_t); + +#define mpz_realloc2 __gmpz_realloc2 +__GMP_DECLSPEC void mpz_realloc2 (mpz_ptr, mp_bitcnt_t); + +#define mpz_remove __gmpz_remove +__GMP_DECLSPEC mp_bitcnt_t mpz_remove (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_root __gmpz_root +__GMP_DECLSPEC int mpz_root (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_rootrem __gmpz_rootrem +__GMP_DECLSPEC void mpz_rootrem (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_rrandomb __gmpz_rrandomb +__GMP_DECLSPEC void mpz_rrandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t); + +#define mpz_scan0 __gmpz_scan0 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan0 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_scan1 __gmpz_scan1 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan1 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_set __gmpz_set +__GMP_DECLSPEC void mpz_set (mpz_ptr, mpz_srcptr); + +#define mpz_set_d __gmpz_set_d +__GMP_DECLSPEC void mpz_set_d (mpz_ptr, double); + +#define mpz_set_f __gmpz_set_f +__GMP_DECLSPEC void mpz_set_f (mpz_ptr, mpf_srcptr); + +#define mpz_set_q __gmpz_set_q +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q) +__GMP_DECLSPEC void mpz_set_q (mpz_ptr, mpq_srcptr); +#endif + +#define mpz_set_si __gmpz_set_si +__GMP_DECLSPEC void mpz_set_si (mpz_ptr, signed long int); + +#define mpz_set_str __gmpz_set_str +__GMP_DECLSPEC int mpz_set_str (mpz_ptr, const char *, int); + +#define mpz_set_ui __gmpz_set_ui +__GMP_DECLSPEC void mpz_set_ui (mpz_ptr, unsigned long int); + +#define mpz_setbit __gmpz_setbit +__GMP_DECLSPEC void mpz_setbit (mpz_ptr, mp_bitcnt_t); + +#define mpz_size __gmpz_size +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size) +__GMP_DECLSPEC size_t mpz_size (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_sizeinbase __gmpz_sizeinbase +__GMP_DECLSPEC size_t mpz_sizeinbase (mpz_srcptr, int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_sqrt __gmpz_sqrt +__GMP_DECLSPEC void mpz_sqrt (mpz_ptr, mpz_srcptr); + +#define mpz_sqrtrem __gmpz_sqrtrem +__GMP_DECLSPEC void mpz_sqrtrem (mpz_ptr, mpz_ptr, mpz_srcptr); + +#define mpz_sub __gmpz_sub +__GMP_DECLSPEC void mpz_sub (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_sub_ui __gmpz_sub_ui +__GMP_DECLSPEC void mpz_sub_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_ui_sub __gmpz_ui_sub +__GMP_DECLSPEC void mpz_ui_sub (mpz_ptr, unsigned long int, mpz_srcptr); + +#define mpz_submul __gmpz_submul +__GMP_DECLSPEC void mpz_submul (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_submul_ui __gmpz_submul_ui +__GMP_DECLSPEC void mpz_submul_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_swap __gmpz_swap +__GMP_DECLSPEC void mpz_swap (mpz_ptr, mpz_ptr) __GMP_NOTHROW; + +#define mpz_tdiv_ui __gmpz_tdiv_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; + +#define mpz_tdiv_q __gmpz_tdiv_q +__GMP_DECLSPEC void mpz_tdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp +__GMP_DECLSPEC void mpz_tdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_tdiv_qr __gmpz_tdiv_qr +__GMP_DECLSPEC void mpz_tdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_tdiv_r __gmpz_tdiv_r +__GMP_DECLSPEC void mpz_tdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp +__GMP_DECLSPEC void mpz_tdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); + +#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); + +#define mpz_tstbit __gmpz_tstbit +__GMP_DECLSPEC int mpz_tstbit (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_ui_pow_ui __gmpz_ui_pow_ui +__GMP_DECLSPEC void mpz_ui_pow_ui (mpz_ptr, unsigned long int, unsigned long int); + +#define mpz_urandomb __gmpz_urandomb +__GMP_DECLSPEC void mpz_urandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t); + +#define mpz_urandomm __gmpz_urandomm +__GMP_DECLSPEC void mpz_urandomm (mpz_ptr, gmp_randstate_t, mpz_srcptr); + +#define mpz_xor __gmpz_xor +#define mpz_eor __gmpz_xor +__GMP_DECLSPEC void mpz_xor (mpz_ptr, mpz_srcptr, mpz_srcptr); + +#define mpz_limbs_read __gmpz_limbs_read +__GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr); + +#define mpz_limbs_write __gmpz_limbs_write +__GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t); + +#define mpz_limbs_modify __gmpz_limbs_modify +__GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t); + +#define mpz_limbs_finish __gmpz_limbs_finish +__GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t); + +#define mpz_roinit_n __gmpz_roinit_n +__GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t); + +#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} + +/**************** Rational (i.e. Q) routines. ****************/ + +#define mpq_abs __gmpq_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs) +__GMP_DECLSPEC void mpq_abs (mpq_ptr, mpq_srcptr); +#endif + +#define mpq_add __gmpq_add +__GMP_DECLSPEC void mpq_add (mpq_ptr, mpq_srcptr, mpq_srcptr); + +#define mpq_canonicalize __gmpq_canonicalize +__GMP_DECLSPEC void mpq_canonicalize (mpq_ptr); + +#define mpq_clear __gmpq_clear +__GMP_DECLSPEC void mpq_clear (mpq_ptr); + +#define mpq_clears __gmpq_clears +__GMP_DECLSPEC void mpq_clears (mpq_ptr, ...); + +#define mpq_cmp __gmpq_cmp +__GMP_DECLSPEC int mpq_cmp (mpq_srcptr, mpq_srcptr) __GMP_ATTRIBUTE_PURE; + +#define _mpq_cmp_si __gmpq_cmp_si +__GMP_DECLSPEC int _mpq_cmp_si (mpq_srcptr, long, unsigned long) __GMP_ATTRIBUTE_PURE; + +#define _mpq_cmp_ui __gmpq_cmp_ui +__GMP_DECLSPEC int _mpq_cmp_ui (mpq_srcptr, unsigned long int, unsigned long int) __GMP_ATTRIBUTE_PURE; + +#define mpq_cmp_z __gmpq_cmp_z +__GMP_DECLSPEC int mpq_cmp_z (mpq_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpq_div __gmpq_div +__GMP_DECLSPEC void mpq_div (mpq_ptr, mpq_srcptr, mpq_srcptr); + +#define mpq_div_2exp __gmpq_div_2exp +__GMP_DECLSPEC void mpq_div_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t); + +#define mpq_equal __gmpq_equal +__GMP_DECLSPEC int mpq_equal (mpq_srcptr, mpq_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpq_get_num __gmpq_get_num +__GMP_DECLSPEC void mpq_get_num (mpz_ptr, mpq_srcptr); + +#define mpq_get_den __gmpq_get_den +__GMP_DECLSPEC void mpq_get_den (mpz_ptr, mpq_srcptr); + +#define mpq_get_d __gmpq_get_d +__GMP_DECLSPEC double mpq_get_d (mpq_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpq_get_str __gmpq_get_str +__GMP_DECLSPEC char *mpq_get_str (char *, int, mpq_srcptr); + +#define mpq_init __gmpq_init +__GMP_DECLSPEC void mpq_init (mpq_ptr); + +#define mpq_inits __gmpq_inits +__GMP_DECLSPEC void mpq_inits (mpq_ptr, ...); + +#define mpq_inp_str __gmpq_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_inp_str (mpq_ptr, FILE *, int); +#endif + +#define mpq_inv __gmpq_inv +__GMP_DECLSPEC void mpq_inv (mpq_ptr, mpq_srcptr); + +#define mpq_mul __gmpq_mul +__GMP_DECLSPEC void mpq_mul (mpq_ptr, mpq_srcptr, mpq_srcptr); + +#define mpq_mul_2exp __gmpq_mul_2exp +__GMP_DECLSPEC void mpq_mul_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t); + +#define mpq_neg __gmpq_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg) +__GMP_DECLSPEC void mpq_neg (mpq_ptr, mpq_srcptr); +#endif + +#define mpq_out_str __gmpq_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_out_str (FILE *, int, mpq_srcptr); +#endif + +#define mpq_set __gmpq_set +__GMP_DECLSPEC void mpq_set (mpq_ptr, mpq_srcptr); + +#define mpq_set_d __gmpq_set_d +__GMP_DECLSPEC void mpq_set_d (mpq_ptr, double); + +#define mpq_set_den __gmpq_set_den +__GMP_DECLSPEC void mpq_set_den (mpq_ptr, mpz_srcptr); + +#define mpq_set_f __gmpq_set_f +__GMP_DECLSPEC void mpq_set_f (mpq_ptr, mpf_srcptr); + +#define mpq_set_num __gmpq_set_num +__GMP_DECLSPEC void mpq_set_num (mpq_ptr, mpz_srcptr); + +#define mpq_set_si __gmpq_set_si +__GMP_DECLSPEC void mpq_set_si (mpq_ptr, signed long int, unsigned long int); + +#define mpq_set_str __gmpq_set_str +__GMP_DECLSPEC int mpq_set_str (mpq_ptr, const char *, int); + +#define mpq_set_ui __gmpq_set_ui +__GMP_DECLSPEC void mpq_set_ui (mpq_ptr, unsigned long int, unsigned long int); + +#define mpq_set_z __gmpq_set_z +__GMP_DECLSPEC void mpq_set_z (mpq_ptr, mpz_srcptr); + +#define mpq_sub __gmpq_sub +__GMP_DECLSPEC void mpq_sub (mpq_ptr, mpq_srcptr, mpq_srcptr); + +#define mpq_swap __gmpq_swap +__GMP_DECLSPEC void mpq_swap (mpq_ptr, mpq_ptr) __GMP_NOTHROW; + + +/**************** Float (i.e. F) routines. ****************/ + +#define mpf_abs __gmpf_abs +__GMP_DECLSPEC void mpf_abs (mpf_ptr, mpf_srcptr); + +#define mpf_add __gmpf_add +__GMP_DECLSPEC void mpf_add (mpf_ptr, mpf_srcptr, mpf_srcptr); + +#define mpf_add_ui __gmpf_add_ui +__GMP_DECLSPEC void mpf_add_ui (mpf_ptr, mpf_srcptr, unsigned long int); +#define mpf_ceil __gmpf_ceil +__GMP_DECLSPEC void mpf_ceil (mpf_ptr, mpf_srcptr); + +#define mpf_clear __gmpf_clear +__GMP_DECLSPEC void mpf_clear (mpf_ptr); + +#define mpf_clears __gmpf_clears +__GMP_DECLSPEC void mpf_clears (mpf_ptr, ...); + +#define mpf_cmp __gmpf_cmp +__GMP_DECLSPEC int mpf_cmp (mpf_srcptr, mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_z __gmpf_cmp_z +__GMP_DECLSPEC int mpf_cmp_z (mpf_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_d __gmpf_cmp_d +__GMP_DECLSPEC int mpf_cmp_d (mpf_srcptr, double) __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_si __gmpf_cmp_si +__GMP_DECLSPEC int mpf_cmp_si (mpf_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_ui __gmpf_cmp_ui +__GMP_DECLSPEC int mpf_cmp_ui (mpf_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_div __gmpf_div +__GMP_DECLSPEC void mpf_div (mpf_ptr, mpf_srcptr, mpf_srcptr); + +#define mpf_div_2exp __gmpf_div_2exp +__GMP_DECLSPEC void mpf_div_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t); + +#define mpf_div_ui __gmpf_div_ui +__GMP_DECLSPEC void mpf_div_ui (mpf_ptr, mpf_srcptr, unsigned long int); + +#define mpf_dump __gmpf_dump +__GMP_DECLSPEC void mpf_dump (mpf_srcptr); + +#define mpf_eq __gmpf_eq +__GMP_DECLSPEC int mpf_eq (mpf_srcptr, mpf_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_sint_p __gmpf_fits_sint_p +__GMP_DECLSPEC int mpf_fits_sint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_slong_p __gmpf_fits_slong_p +__GMP_DECLSPEC int mpf_fits_slong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_sshort_p __gmpf_fits_sshort_p +__GMP_DECLSPEC int mpf_fits_sshort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_uint_p __gmpf_fits_uint_p +__GMP_DECLSPEC int mpf_fits_uint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_ulong_p __gmpf_fits_ulong_p +__GMP_DECLSPEC int mpf_fits_ulong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_ushort_p __gmpf_fits_ushort_p +__GMP_DECLSPEC int mpf_fits_ushort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_floor __gmpf_floor +__GMP_DECLSPEC void mpf_floor (mpf_ptr, mpf_srcptr); + +#define mpf_get_d __gmpf_get_d +__GMP_DECLSPEC double mpf_get_d (mpf_srcptr) __GMP_ATTRIBUTE_PURE; + +#define mpf_get_d_2exp __gmpf_get_d_2exp +__GMP_DECLSPEC double mpf_get_d_2exp (signed long int *, mpf_srcptr); + +#define mpf_get_default_prec __gmpf_get_default_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_default_prec (void) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_prec __gmpf_get_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_prec (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_si __gmpf_get_si +__GMP_DECLSPEC long mpf_get_si (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_str __gmpf_get_str +__GMP_DECLSPEC char *mpf_get_str (char *, mp_exp_t *, int, size_t, mpf_srcptr); + +#define mpf_get_ui __gmpf_get_ui +__GMP_DECLSPEC unsigned long mpf_get_ui (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_init __gmpf_init +__GMP_DECLSPEC void mpf_init (mpf_ptr); + +#define mpf_init2 __gmpf_init2 +__GMP_DECLSPEC void mpf_init2 (mpf_ptr, mp_bitcnt_t); + +#define mpf_inits __gmpf_inits +__GMP_DECLSPEC void mpf_inits (mpf_ptr, ...); + +#define mpf_init_set __gmpf_init_set +__GMP_DECLSPEC void mpf_init_set (mpf_ptr, mpf_srcptr); + +#define mpf_init_set_d __gmpf_init_set_d +__GMP_DECLSPEC void mpf_init_set_d (mpf_ptr, double); + +#define mpf_init_set_si __gmpf_init_set_si +__GMP_DECLSPEC void mpf_init_set_si (mpf_ptr, signed long int); + +#define mpf_init_set_str __gmpf_init_set_str +__GMP_DECLSPEC int mpf_init_set_str (mpf_ptr, const char *, int); + +#define mpf_init_set_ui __gmpf_init_set_ui +__GMP_DECLSPEC void mpf_init_set_ui (mpf_ptr, unsigned long int); + +#define mpf_inp_str __gmpf_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_inp_str (mpf_ptr, FILE *, int); +#endif + +#define mpf_integer_p __gmpf_integer_p +__GMP_DECLSPEC int mpf_integer_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_mul __gmpf_mul +__GMP_DECLSPEC void mpf_mul (mpf_ptr, mpf_srcptr, mpf_srcptr); + +#define mpf_mul_2exp __gmpf_mul_2exp +__GMP_DECLSPEC void mpf_mul_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t); + +#define mpf_mul_ui __gmpf_mul_ui +__GMP_DECLSPEC void mpf_mul_ui (mpf_ptr, mpf_srcptr, unsigned long int); + +#define mpf_neg __gmpf_neg +__GMP_DECLSPEC void mpf_neg (mpf_ptr, mpf_srcptr); + +#define mpf_out_str __gmpf_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_out_str (FILE *, int, size_t, mpf_srcptr); +#endif + +#define mpf_pow_ui __gmpf_pow_ui +__GMP_DECLSPEC void mpf_pow_ui (mpf_ptr, mpf_srcptr, unsigned long int); + +#define mpf_random2 __gmpf_random2 +__GMP_DECLSPEC void mpf_random2 (mpf_ptr, mp_size_t, mp_exp_t); + +#define mpf_reldiff __gmpf_reldiff +__GMP_DECLSPEC void mpf_reldiff (mpf_ptr, mpf_srcptr, mpf_srcptr); + +#define mpf_set __gmpf_set +__GMP_DECLSPEC void mpf_set (mpf_ptr, mpf_srcptr); + +#define mpf_set_d __gmpf_set_d +__GMP_DECLSPEC void mpf_set_d (mpf_ptr, double); + +#define mpf_set_default_prec __gmpf_set_default_prec +__GMP_DECLSPEC void mpf_set_default_prec (mp_bitcnt_t) __GMP_NOTHROW; + +#define mpf_set_prec __gmpf_set_prec +__GMP_DECLSPEC void mpf_set_prec (mpf_ptr, mp_bitcnt_t); + +#define mpf_set_prec_raw __gmpf_set_prec_raw +__GMP_DECLSPEC void mpf_set_prec_raw (mpf_ptr, mp_bitcnt_t) __GMP_NOTHROW; + +#define mpf_set_q __gmpf_set_q +__GMP_DECLSPEC void mpf_set_q (mpf_ptr, mpq_srcptr); + +#define mpf_set_si __gmpf_set_si +__GMP_DECLSPEC void mpf_set_si (mpf_ptr, signed long int); + +#define mpf_set_str __gmpf_set_str +__GMP_DECLSPEC int mpf_set_str (mpf_ptr, const char *, int); + +#define mpf_set_ui __gmpf_set_ui +__GMP_DECLSPEC void mpf_set_ui (mpf_ptr, unsigned long int); + +#define mpf_set_z __gmpf_set_z +__GMP_DECLSPEC void mpf_set_z (mpf_ptr, mpz_srcptr); + +#define mpf_size __gmpf_size +__GMP_DECLSPEC size_t mpf_size (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_sqrt __gmpf_sqrt +__GMP_DECLSPEC void mpf_sqrt (mpf_ptr, mpf_srcptr); + +#define mpf_sqrt_ui __gmpf_sqrt_ui +__GMP_DECLSPEC void mpf_sqrt_ui (mpf_ptr, unsigned long int); + +#define mpf_sub __gmpf_sub +__GMP_DECLSPEC void mpf_sub (mpf_ptr, mpf_srcptr, mpf_srcptr); + +#define mpf_sub_ui __gmpf_sub_ui +__GMP_DECLSPEC void mpf_sub_ui (mpf_ptr, mpf_srcptr, unsigned long int); + +#define mpf_swap __gmpf_swap +__GMP_DECLSPEC void mpf_swap (mpf_ptr, mpf_ptr) __GMP_NOTHROW; + +#define mpf_trunc __gmpf_trunc +__GMP_DECLSPEC void mpf_trunc (mpf_ptr, mpf_srcptr); + +#define mpf_ui_div __gmpf_ui_div +__GMP_DECLSPEC void mpf_ui_div (mpf_ptr, unsigned long int, mpf_srcptr); + +#define mpf_ui_sub __gmpf_ui_sub +__GMP_DECLSPEC void mpf_ui_sub (mpf_ptr, unsigned long int, mpf_srcptr); + +#define mpf_urandomb __gmpf_urandomb +__GMP_DECLSPEC void mpf_urandomb (mpf_t, gmp_randstate_t, mp_bitcnt_t); + + +/************ Low level positive-integer (i.e. N) routines. ************/ + +/* This is ugly, but we need to make user calls reach the prefixed function. */ + +#define mpn_add __MPN(add) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add) +__GMP_DECLSPEC mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); +#endif + +#define mpn_add_1 __MPN(add_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1) +__GMP_DECLSPEC mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW; +#endif + +#define mpn_add_n __MPN(add_n) +__GMP_DECLSPEC mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); + +#define mpn_addmul_1 __MPN(addmul_1) +__GMP_DECLSPEC mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_cmp __MPN(cmp) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp) +__GMP_DECLSPEC int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpn_zero_p __MPN(zero_p) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_zero_p) +__GMP_DECLSPEC int mpn_zero_p (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpn_divexact_1 __MPN(divexact_1) +__GMP_DECLSPEC void mpn_divexact_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_divexact_by3(dst,src,size) \ + mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0)) + +#define mpn_divexact_by3c __MPN(divexact_by3c) +__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_divmod_1(qp,np,nsize,dlimb) \ + mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb) + +#define mpn_divrem __MPN(divrem) +__GMP_DECLSPEC mp_limb_t mpn_divrem (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t); + +#define mpn_divrem_1 __MPN(divrem_1) +__GMP_DECLSPEC mp_limb_t mpn_divrem_1 (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_divrem_2 __MPN(divrem_2) +__GMP_DECLSPEC mp_limb_t mpn_divrem_2 (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr); + +#define mpn_div_qr_1 __MPN(div_qr_1) +__GMP_DECLSPEC mp_limb_t mpn_div_qr_1 (mp_ptr, mp_limb_t *, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_div_qr_2 __MPN(div_qr_2) +__GMP_DECLSPEC mp_limb_t mpn_div_qr_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr); + +#define mpn_gcd __MPN(gcd) +__GMP_DECLSPEC mp_size_t mpn_gcd (mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t); + +#define mpn_gcd_11 __MPN(gcd_11) +__GMP_DECLSPEC mp_limb_t mpn_gcd_11 (mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_gcd_1 __MPN(gcd_1) +__GMP_DECLSPEC mp_limb_t mpn_gcd_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_gcdext_1 __MPN(gcdext_1) +__GMP_DECLSPEC mp_limb_t mpn_gcdext_1 (mp_limb_signed_t *, mp_limb_signed_t *, mp_limb_t, mp_limb_t); + +#define mpn_gcdext __MPN(gcdext) +__GMP_DECLSPEC mp_size_t mpn_gcdext (mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t); + +#define mpn_get_str __MPN(get_str) +__GMP_DECLSPEC size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t); + +#define mpn_hamdist __MPN(hamdist) +__GMP_DECLSPEC mp_bitcnt_t mpn_hamdist (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpn_lshift __MPN(lshift) +__GMP_DECLSPEC mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); + +#define mpn_mod_1 __MPN(mod_1) +__GMP_DECLSPEC mp_limb_t mpn_mod_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_mul __MPN(mul) +__GMP_DECLSPEC mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); + +#define mpn_mul_1 __MPN(mul_1) +__GMP_DECLSPEC mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_mul_n __MPN(mul_n) +__GMP_DECLSPEC void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); + +#define mpn_sqr __MPN(sqr) +__GMP_DECLSPEC void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t); + +#define mpn_neg __MPN(neg) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_neg) +__GMP_DECLSPEC mp_limb_t mpn_neg (mp_ptr, mp_srcptr, mp_size_t); +#endif + +#define mpn_com __MPN(com) +__GMP_DECLSPEC void mpn_com (mp_ptr, mp_srcptr, mp_size_t); + +#define mpn_perfect_square_p __MPN(perfect_square_p) +__GMP_DECLSPEC int mpn_perfect_square_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_perfect_power_p __MPN(perfect_power_p) +__GMP_DECLSPEC int mpn_perfect_power_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_popcount __MPN(popcount) +__GMP_DECLSPEC mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpn_pow_1 __MPN(pow_1) +__GMP_DECLSPEC mp_size_t mpn_pow_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); + +/* undocumented now, but retained here for upward compatibility */ +#define mpn_preinv_mod_1 __MPN(preinv_mod_1) +__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 (mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_random __MPN(random) +__GMP_DECLSPEC void mpn_random (mp_ptr, mp_size_t); + +#define mpn_random2 __MPN(random2) +__GMP_DECLSPEC void mpn_random2 (mp_ptr, mp_size_t); + +#define mpn_rshift __MPN(rshift) +__GMP_DECLSPEC mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); + +#define mpn_scan0 __MPN(scan0) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_scan1 __MPN(scan1) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_set_str __MPN(set_str) +__GMP_DECLSPEC mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int); + +#define mpn_sizeinbase __MPN(sizeinbase) +__GMP_DECLSPEC size_t mpn_sizeinbase (mp_srcptr, mp_size_t, int); + +#define mpn_sqrtrem __MPN(sqrtrem) +__GMP_DECLSPEC mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t); + +#define mpn_sub __MPN(sub) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub) +__GMP_DECLSPEC mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); +#endif + +#define mpn_sub_1 __MPN(sub_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1) +__GMP_DECLSPEC mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW; +#endif + +#define mpn_sub_n __MPN(sub_n) +__GMP_DECLSPEC mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); + +#define mpn_submul_1 __MPN(submul_1) +__GMP_DECLSPEC mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); + +#define mpn_tdiv_qr __MPN(tdiv_qr) +__GMP_DECLSPEC void mpn_tdiv_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); + +#define mpn_and_n __MPN(and_n) +__GMP_DECLSPEC void mpn_and_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_andn_n __MPN(andn_n) +__GMP_DECLSPEC void mpn_andn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_nand_n __MPN(nand_n) +__GMP_DECLSPEC void mpn_nand_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_ior_n __MPN(ior_n) +__GMP_DECLSPEC void mpn_ior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_iorn_n __MPN(iorn_n) +__GMP_DECLSPEC void mpn_iorn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_nior_n __MPN(nior_n) +__GMP_DECLSPEC void mpn_nior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_xor_n __MPN(xor_n) +__GMP_DECLSPEC void mpn_xor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_xnor_n __MPN(xnor_n) +__GMP_DECLSPEC void mpn_xnor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); + +#define mpn_copyi __MPN(copyi) +__GMP_DECLSPEC void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t); +#define mpn_copyd __MPN(copyd) +__GMP_DECLSPEC void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t); +#define mpn_zero __MPN(zero) +__GMP_DECLSPEC void mpn_zero (mp_ptr, mp_size_t); + +#define mpn_cnd_add_n __MPN(cnd_add_n) +__GMP_DECLSPEC mp_limb_t mpn_cnd_add_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); +#define mpn_cnd_sub_n __MPN(cnd_sub_n) +__GMP_DECLSPEC mp_limb_t mpn_cnd_sub_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); + +#define mpn_sec_add_1 __MPN(sec_add_1) +__GMP_DECLSPEC mp_limb_t mpn_sec_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); +#define mpn_sec_add_1_itch __MPN(sec_add_1_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_add_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_sec_sub_1 __MPN(sec_sub_1) +__GMP_DECLSPEC mp_limb_t mpn_sec_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); +#define mpn_sec_sub_1_itch __MPN(sec_sub_1_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_sub_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_cnd_swap __MPN(cnd_swap) +__GMP_DECLSPEC void mpn_cnd_swap (mp_limb_t, volatile mp_limb_t *, volatile mp_limb_t *, mp_size_t); + +#define mpn_sec_mul __MPN(sec_mul) +__GMP_DECLSPEC void mpn_sec_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); +#define mpn_sec_mul_itch __MPN(sec_mul_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_mul_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_sec_sqr __MPN(sec_sqr) +__GMP_DECLSPEC void mpn_sec_sqr (mp_ptr, mp_srcptr, mp_size_t, mp_ptr); +#define mpn_sec_sqr_itch __MPN(sec_sqr_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_sqr_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_sec_powm __MPN(sec_powm) +__GMP_DECLSPEC void mpn_sec_powm (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_bitcnt_t, mp_srcptr, mp_size_t, mp_ptr); +#define mpn_sec_powm_itch __MPN(sec_powm_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_powm_itch (mp_size_t, mp_bitcnt_t, mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_sec_tabselect __MPN(sec_tabselect) +__GMP_DECLSPEC void mpn_sec_tabselect (volatile mp_limb_t *, volatile const mp_limb_t *, mp_size_t, mp_size_t, mp_size_t); + +#define mpn_sec_div_qr __MPN(sec_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_sec_div_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); +#define mpn_sec_div_qr_itch __MPN(sec_div_qr_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_div_qr_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; +#define mpn_sec_div_r __MPN(sec_div_r) +__GMP_DECLSPEC void mpn_sec_div_r (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); +#define mpn_sec_div_r_itch __MPN(sec_div_r_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_div_r_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; + +#define mpn_sec_invert __MPN(sec_invert) +__GMP_DECLSPEC int mpn_sec_invert (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_bitcnt_t, mp_ptr); +#define mpn_sec_invert_itch __MPN(sec_invert_itch) +__GMP_DECLSPEC mp_size_t mpn_sec_invert_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; + + +/**************** mpz inlines ****************/ + +/* The following are provided as inlines where possible, but always exist as + library functions too, for binary compatibility. + + Within gmp itself this inlining generally isn't relied on, since it + doesn't get done for all compilers, whereas if something is worth + inlining then it's worth arranging always. + + There are two styles of inlining here. When the same bit of code is + wanted for the inline as for the library version, then __GMP_FORCE_foo + arranges for that code to be emitted and the __GMP_EXTERN_INLINE + directive suppressed, eg. mpz_fits_uint_p. When a different bit of code + is wanted for the inline than for the library version, then + __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */ + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs) +__GMP_EXTERN_INLINE void +mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size); +} +#endif + +#if GMP_NAIL_BITS == 0 +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)); +#else +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \ + || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS))); +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p) +#if ! defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, UINT_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p) +#if ! defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, ULONG_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p) +#if ! defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, USHRT_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui) +#if ! defined (__GMP_FORCE_mpz_get_ui) +__GMP_EXTERN_INLINE +#endif +unsigned long +mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + mp_ptr __gmp_p = __gmp_z->_mp_d; + mp_size_t __gmp_n = __gmp_z->_mp_size; + mp_limb_t __gmp_l = __gmp_p[0]; + /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings + about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland + C++ 6.0 warnings about condition always true for something like + "ULONG_MAX < GMP_NUMB_MASK". */ +#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB) + /* limb==long and no nails, or limb==longlong, one limb is enough */ + return (__gmp_n != 0 ? __gmp_l : 0); +#else + /* limb==long and nails, need two limbs when available */ + __gmp_n = __GMP_ABS (__gmp_n); + if (__gmp_n <= 1) + return (__gmp_n != 0 ? __gmp_l : 0); + else + return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS); +#endif +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn) +#if ! defined (__GMP_FORCE_mpz_getlimbn) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_result = 0; + if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size))) + __gmp_result = __gmp_z->_mp_d[__gmp_n]; + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg) +__GMP_EXTERN_INLINE void +mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = - __gmp_w->_mp_size; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p) +#if ! defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_perfect_square_p (mpz_srcptr __gmp_a) +{ + mp_size_t __gmp_asize; + int __gmp_result; + + __gmp_asize = __gmp_a->_mp_size; + __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */ + if (__GMP_LIKELY (__gmp_asize > 0)) + __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount) +#if ! defined (__GMP_FORCE_mpz_popcount) +__GMP_EXTERN_INLINE +#endif +mp_bitcnt_t +mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW +{ + mp_size_t __gmp_usize; + mp_bitcnt_t __gmp_result; + + __gmp_usize = __gmp_u->_mp_size; + __gmp_result = (__gmp_usize < 0 ? ~ __GMP_CAST (mp_bitcnt_t, 0) : __GMP_CAST (mp_bitcnt_t, 0)); + if (__GMP_LIKELY (__gmp_usize > 0)) + __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q) +#if ! defined (__GMP_FORCE_mpz_set_q) +__GMP_EXTERN_INLINE +#endif +void +mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u)); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size) +#if ! defined (__GMP_FORCE_mpz_size) +__GMP_EXTERN_INLINE +#endif +size_t +mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + return __GMP_ABS (__gmp_z->_mp_size); +} +#endif + + +/**************** mpq inlines ****************/ + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs) +__GMP_EXTERN_INLINE void +mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg) +__GMP_EXTERN_INLINE void +mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size; +} +#endif + + +/**************** mpn inlines ****************/ + +/* The comments with __GMPN_ADD_1 below apply here too. + + The test for FUNCTION returning 0 should predict well. If it's assumed + {yp,ysize} will usually have a random number of bits then the high limb + won't be full and a carry out will occur a good deal less than 50% of the + time. + + ysize==0 isn't a documented feature, but is used internally in a few + places. + + Producing cout last stops it using up a register during the main part of + the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))" + doesn't seem able to move the true and false legs of the conditional up + to the two places cout is generated. */ + +#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x; \ + \ + /* ASSERT ((ysize) >= 0); */ \ + /* ASSERT ((xsize) >= (ysize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \ + \ + __gmp_i = (ysize); \ + if (__gmp_i != 0) \ + { \ + if (FUNCTION (wp, xp, yp, __gmp_i)) \ + { \ + do \ + { \ + if (__gmp_i >= (xsize)) \ + { \ + (cout) = 1; \ + goto __gmp_done; \ + } \ + __gmp_x = (xp)[__gmp_i]; \ + } \ + while (TEST); \ + } \ + } \ + if ((wp) != (xp)) \ + __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \ + (cout) = 0; \ + __gmp_done: \ + ; \ + } while (0) + +#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \ + (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0)) +#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \ + (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0)) + + +/* The use of __gmp_i indexing is designed to ensure a compile time src==dst + remains nice and clear to the compiler, so that __GMPN_COPY_REST can + disappear, and the load/add/store gets a chance to become a + read-modify-write on CISC CPUs. + + Alternatives: + + Using a pair of pointers instead of indexing would be possible, but gcc + isn't able to recognise compile-time src==dst in that case, even when the + pointers are incremented more or less together. Other compilers would + very likely have similar difficulty. + + gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or + similar to detect a compile-time src==dst. This works nicely on gcc + 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems + to be always false, for a pointer p. But the current code form seems + good enough for src==dst anyway. + + gcc on x86 as usual doesn't give particularly good flags handling for the + carry/borrow detection. It's tempting to want some multi instruction asm + blocks to help it, and this was tried, but in truth there's only a few + instructions to save and any gain is all too easily lost by register + juggling setting up for the asm. */ + +#if GMP_NAIL_BITS == 0 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r; \ + if (CB (__gmp_r, __gmp_x, (v))) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r; \ + ++__gmp_i; \ + if (!CB (__gmp_r, __gmp_x, 1)) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif + +#if GMP_NAIL_BITS >= 1 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r & GMP_NUMB_MASK; \ + if (__gmp_r >> GMP_NUMB_BITS != 0) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \ + ++__gmp_i; \ + if (__gmp_r >> GMP_NUMB_BITS == 0) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif + +#define __GMPN_ADDCB(r,x,y) ((r) < (y)) +#define __GMPN_SUBCB(r,x,y) ((x) < (y)) + +#define __GMPN_ADD_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB) +#define __GMPN_SUB_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB) + + +/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or + negative. size==0 is allowed. On random data usually only one limb will + need to be examined to get a result, so it's worth having it inline. */ +#define __GMPN_CMP(result, xp, yp, size) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_y; \ + \ + /* ASSERT ((size) >= 0); */ \ + \ + (result) = 0; \ + __gmp_i = (size); \ + while (--__gmp_i >= 0) \ + { \ + __gmp_x = (xp)[__gmp_i]; \ + __gmp_y = (yp)[__gmp_i]; \ + if (__gmp_x != __gmp_y) \ + { \ + /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \ + (result) = (__gmp_x > __gmp_y ? 1 : -1); \ + break; \ + } \ + } \ + } while (0) + + +#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \ + } while (0) +#endif + +/* Copy {src,size} to {dst,size}, starting at "start". This is designed to + keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1, + __GMPN_ADD, etc. */ +#if ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + mp_size_t __gmp_j; \ + /* ASSERT ((size) >= 0); */ \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \ + __GMP_CRAY_Pragma ("_CRI ivdep"); \ + for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \ + (dst)[__gmp_j] = (src)[__gmp_j]; \ + } while (0) +#endif + +/* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use + mpn_copyi if there's a native version, and if we don't mind demanding + binary compatibility for it (on targets which use it). */ + +#if ! defined (__GMPN_COPY) +#define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0) +#endif + + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add) +#if ! defined (__GMP_FORCE_mpn_add) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1) +#if ! defined (__GMP_FORCE_mpn_add_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp) +#if ! defined (__GMP_FORCE_mpn_cmp) +__GMP_EXTERN_INLINE +#endif +int +mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW +{ + int __gmp_result; + __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_zero_p) +#if ! defined (__GMP_FORCE_mpn_zero_p) +__GMP_EXTERN_INLINE +#endif +int +mpn_zero_p (mp_srcptr __gmp_p, mp_size_t __gmp_n) __GMP_NOTHROW +{ + /* if (__GMP_LIKELY (__gmp_n > 0)) */ + do { + if (__gmp_p[--__gmp_n] != 0) + return 0; + } while (__gmp_n != 0); + return 1; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub) +#if ! defined (__GMP_FORCE_mpn_sub) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1) +#if ! defined (__GMP_FORCE_mpn_sub_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_neg) +#if ! defined (__GMP_FORCE_mpn_neg) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n) +{ + while (*__gmp_up == 0) /* Low zero limbs are unchanged by negation. */ + { + *__gmp_rp = 0; + if (!--__gmp_n) /* All zero */ + return 0; + ++__gmp_up; ++__gmp_rp; + } + + *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK; + + if (--__gmp_n) /* Higher limbs get complemented. */ + mpn_com (++__gmp_rp, ++__gmp_up, __gmp_n); + + return 1; +} +#endif + +#if defined (__cplusplus) +} +#endif + + +/* Allow faster testing for negative, zero, and positive. */ +#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) +#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) +#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) + +/* When using GCC, optimize certain common comparisons. */ +#if defined (__GNUC__) && __GNUC__ >= 2 +#define mpz_cmp_ui(Z,UI) \ + (__builtin_constant_p (UI) && (UI) == 0 \ + ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) +#define mpz_cmp_si(Z,SI) \ + (__builtin_constant_p ((SI) >= 0) && (SI) >= 0 \ + ? mpz_cmp_ui (Z, __GMP_CAST (unsigned long, SI)) \ + : _mpz_cmp_si (Z,SI)) +#define mpq_cmp_ui(Q,NUI,DUI) \ + (__builtin_constant_p (NUI) && (NUI) == 0 ? mpq_sgn (Q) \ + : __builtin_constant_p ((NUI) == (DUI)) && (NUI) == (DUI) \ + ? mpz_cmp (mpq_numref (Q), mpq_denref (Q)) \ + : _mpq_cmp_ui (Q,NUI,DUI)) +#define mpq_cmp_si(q,n,d) \ + (__builtin_constant_p ((n) >= 0) && (n) >= 0 \ + ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \ + : _mpq_cmp_si (q, n, d)) +#else +#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) +#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) +#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) +#define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d) +#endif + + +/* Using "&" rather than "&&" means these can come out branch-free. Every + mpz_t has at least one limb allocated, so fetching the low limb is always + allowed. */ +#define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0])) +#define mpz_even_p(z) (! mpz_odd_p (z)) + + +/**************** C++ routines ****************/ + +#ifdef __cplusplus +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr); +#endif + + +/* Source-level compatibility with GMP 2 and earlier. */ +#define mpn_divmod(qp,np,nsize,dp,dsize) \ + mpn_divrem (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dp, dsize) + +/* Source-level compatibility with GMP 1. */ +#define mpz_mdiv mpz_fdiv_q +#define mpz_mdivmod mpz_fdiv_qr +#define mpz_mmod mpz_fdiv_r +#define mpz_mdiv_ui mpz_fdiv_q_ui +#define mpz_mdivmod_ui(q,r,n,d) \ + (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) +#define mpz_mmod_ui(r,n,d) \ + (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) + +/* Useful synonyms, but not quite compatible with GMP 1. */ +#define mpz_div mpz_fdiv_q +#define mpz_divmod mpz_fdiv_qr +#define mpz_div_ui mpz_fdiv_q_ui +#define mpz_divmod_ui mpz_fdiv_qr_ui +#define mpz_div_2exp mpz_fdiv_q_2exp +#define mpz_mod_2exp mpz_fdiv_r_2exp + +enum +{ + GMP_ERROR_NONE = 0, + GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, + GMP_ERROR_DIVISION_BY_ZERO = 2, + GMP_ERROR_SQRT_OF_NEGATIVE = 4, + GMP_ERROR_INVALID_ARGUMENT = 8 +}; + +/* Define CC and CFLAGS which were used to build this version of GMP */ +#define __GMP_CC "x86_64-linux-gnu-gcc" +#define __GMP_CFLAGS "-g -O2 -fdebug-prefix-map=/build/gmp-xrY6Wh/gmp-6.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -O3" + +/* Major version number is the value of __GNU_MP__ too, above. */ +#define __GNU_MP_VERSION 6 +#define __GNU_MP_VERSION_MINOR 2 +#define __GNU_MP_VERSION_PATCHLEVEL 0 +#define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL) + +#define __GMP_H__ +#endif /* __GMP_H__ */ From d2e14a65d54d016fbc4a6db87f361b12f1c981d0 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 10:34:00 +0200 Subject: [PATCH 07/51] Moved `Find*.cmake` to ./cmake, removed `set(CMAKE_MODULE_PATH ".")` --- CMakeLists.txt | 2 -- FindGMP.cmake => cmake/FindGMP.cmake | 2 +- FindMySQL.cmake => cmake/FindMySQL.cmake | 0 3 files changed, 1 insertion(+), 3 deletions(-) rename FindGMP.cmake => cmake/FindGMP.cmake (98%) rename FindMySQL.cmake => cmake/FindMySQL.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d34ea..36287fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,8 +67,6 @@ include(CTest) include(c) -set(CMAKE_MODULE_PATH ".") - option(WITH_GMP "use GNU MP bignum library" OFF) if(WITH_GMP) find_package(GMP) diff --git a/FindGMP.cmake b/cmake/FindGMP.cmake similarity index 98% rename from FindGMP.cmake rename to cmake/FindGMP.cmake index cad534f..d9e249a 100644 --- a/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -46,7 +46,7 @@ find_library( GMP_LIBRARY "C:\\Windows\\System32" ) if (GMP_LIBRARY) - set(GMP_INCLUDE_DIR include) + set(GMP_INCLUDE_DIR ../include) endif() # handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE if diff --git a/FindMySQL.cmake b/cmake/FindMySQL.cmake similarity index 100% rename from FindMySQL.cmake rename to cmake/FindMySQL.cmake From 7f7a608e9c6c7aae004bfb128a80af50a1a5d3ad Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 13:56:54 +0200 Subject: [PATCH 08/51] added `glpsol` executable target plus tests --- CMakeLists.txt | 10 +++---- examples/CMakeLists.txt | 2 +- src/CMakeLists.txt | 47 +++++++++++++++++++++++++++++ src/amd/CMakeLists.txt | 18 ++++++++++++ src/api/CMakeLists.txt | 59 +++++++++++++++++++++++++++++++++++++ src/bflib/CMakeLists.txt | 26 +++++++++++++++++ src/colamd/CMakeLists.txt | 6 ++++ src/draft/CMakeLists.txt | 34 +++++++++++++++++++++ src/env/CMakeLists.txt | 15 ++++++++++ src/intopt/CMakeLists.txt | 16 ++++++++++ src/minisat/CMakeLists.txt | 6 ++++ src/misc/CMakeLists.txt | 60 ++++++++++++++++++++++++++++++++++++++ src/mpl/CMakeLists.txt | 13 +++++++++ src/npp/CMakeLists.txt | 11 +++++++ src/proxy/CMakeLists.txt | 7 +++++ src/simplex/CMakeLists.txt | 23 +++++++++++++++ src/zlib/CMakeLists.txt | 31 ++++++++++++++++++++ 17 files changed, 378 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36287fd..c9b6d53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,10 @@ include(CTest) include(c) +option(BUILD_EXAMPLES "Build examples" ON) +message(STATUS "Build examples: ${BUILD_EXAMPLES}") +add_subdirectory(examples) + option(WITH_GMP "use GNU MP bignum library" OFF) if(WITH_GMP) find_package(GMP) @@ -136,8 +140,4 @@ if(IS_REENTRANT) set(TLS "_Thread_local") # default to C11 standard, may break some builds if TLS isn't supported endif() add_compile_definitions(TLS=${TLS}) -endif() - -option(BUILD_EXAMPLES "Build examples" ON) -message(STATUS "Build examples: ${BUILD_EXAMPLES}") -add_subdirectory(examples) +endif() \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f726777..da51b0d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,4 +7,4 @@ list(FILTER C_SRCS EXCLUDE REGEX ".*/glpsol.c") # need input file list(FILTER C_SRCS EXCLUDE REGEX ".*/netgen.c") # no license foreach(FILE_NAME IN LISTS C_SRCS) add_c_example(${FILE_NAME}) -endforeach() +endforeach() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a80c08d..6539916 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,12 @@ add_library(GLPK) +add_executable(GLPSOL) target_sources(GLPK PRIVATE glpk.h) +target_sources(GLPSOL + PRIVATE + ../examples/glpsol.c + PRIVATE + glpk.h +) add_subdirectory(amd) add_subdirectory(api) add_subdirectory(bflib) @@ -42,6 +49,45 @@ target_link_libraries(GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) +target_include_directories(GLPSOL + PUBLIC + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) +target_compile_features(GLPSOL PUBLIC c_std_11) +set_target_properties(GLPSOL PROPERTIES + VERSION ${PROJECT_VERSION} + PUBLIC_HEADER glpk.h) # not sure about this one +target_link_libraries(GLPSOL + PRIVATE + $<$>:m>) +add_executable(${PROJECT_NAMESPACE}::GLPSOL ALIAS GLPSOL) +add_test( + NAME + glpsol_version + COMMAND + GLPSOL --version +) +add_test( + NAME + glpsol_solve + COMMAND + GLPSOL --mps ${CMAKE_SOURCE_DIR}/examples/murtagh.mps --max +) + # check system libs functions and headers # m::exp include(CheckSymbolExists) @@ -52,6 +98,7 @@ if(NOT HAVE_EXP) check_symbol_exists(exp "math.h" HAVE_EXP) if(HAVE_EXP) target_link_libraries(GLPK PRIVATE m) + target_link_libraries(GLPSOL PRIVATE m) else() message(FATAL_ERROR "exp function not found") endif() diff --git a/src/amd/CMakeLists.txt b/src/amd/CMakeLists.txt index e231731..6d5105f 100644 --- a/src/amd/CMakeLists.txt +++ b/src/amd/CMakeLists.txt @@ -15,3 +15,21 @@ target_sources(GLPK amd_preprocess.c amd_valid.c ) + +target_sources(GLPSOL + PRIVATE + amd_1.c + amd_2.c + amd_aat.c + amd_control.c + amd_defaults.c + amd_dump.c + amd.h + amd_info.c + amd_internal.h + amd_order.c + amd_postorder.c + amd_post_tree.c + amd_preprocess.c + amd_valid.c +) \ No newline at end of file diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index c19d4a9..6543a19 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -56,3 +56,62 @@ target_sources(GLPK wrprob.c wrsol.c ) + +target_sources(GLPSOL + PRIVATE + advbas.c + asnhall.c + asnlp.c + asnokalg.c + ckasn.c + ckcnf.c + cplex.c + cpp.c + cpxbas.c + graph.c + gridgen.c + intfeas1.c + maxffalg.c + maxflp.c + mcflp.c + mcfokalg.c + mcfrelax.c + minisat1.c + mpl.c + mps.c + netgen.c + npp.c + pript.c + prmip.c + prob1.c + prob2.c + prob3.c + prob4.c + prob5.c + prob.h + prrngs.c + prsol.c + rdasn.c + rdcc.c + rdcnf.c + rdipt.c + rdmaxf.c + rdmcf.c + rdmip.c + rdprob.c + rdsol.c + rmfgen.c + strong.c + topsort.c + wcliqex.c + weak.c + wrasn.c + wrcc.c + wrcnf.c + wript.c + wrmaxf.c + wrmcf.c + wrmip.c + wrprob.c + wrsol.c +) \ No newline at end of file diff --git a/src/bflib/CMakeLists.txt b/src/bflib/CMakeLists.txt index 47a77e7..8b415ad 100644 --- a/src/bflib/CMakeLists.txt +++ b/src/bflib/CMakeLists.txt @@ -23,3 +23,29 @@ target_sources(GLPK sva.c sva.h ) + +target_sources(GLPSOL + PRIVATE + btf.c + btf.h + btfint.c + btfint.h + fhv.c + fhv.h + fhvint.c + fhvint.h + ifu.c + ifu.h + luf.c + luf.h + lufint.c + lufint.h + scf.c + scf.h + scfint.c + scfint.h + sgf.c + sgf.h + sva.c + sva.h +) \ No newline at end of file diff --git a/src/colamd/CMakeLists.txt b/src/colamd/CMakeLists.txt index 76e4cc4..440a8bb 100644 --- a/src/colamd/CMakeLists.txt +++ b/src/colamd/CMakeLists.txt @@ -3,3 +3,9 @@ target_sources(GLPK colamd.c colamd.h ) + +target_sources(GLPSOL + PRIVATE + colamd.c + colamd.h +) \ No newline at end of file diff --git a/src/draft/CMakeLists.txt b/src/draft/CMakeLists.txt index 669f4f4..d1c7c4c 100644 --- a/src/draft/CMakeLists.txt +++ b/src/draft/CMakeLists.txt @@ -31,3 +31,37 @@ target_sources(GLPK lux.c lux.h ) + +target_sources(GLPSOL + PRIVATE + bfd.c + bfd.h + bfx.c + bfx.h + draft.h + glpapi06.c + glpapi07.c + glpapi08.c + glpapi09.c + glpapi10.c + glpapi12.c + glpapi13.c + glpios01.c + glpios02.c + glpios03.c + glpios07.c + glpios09.c + glpios11.c + glpios12.c + glpipm.c + glpipm.h + glpmat.c + glpmat.h + glpscl.c + glpssx01.c + glpssx02.c + glpssx.h + ios.h + lux.c + lux.h +) \ No newline at end of file diff --git a/src/env/CMakeLists.txt b/src/env/CMakeLists.txt index 27b6f9d..1d3cff5 100644 --- a/src/env/CMakeLists.txt +++ b/src/env/CMakeLists.txt @@ -12,3 +12,18 @@ target_sources(GLPK time.c tls.c ) + +target_sources(GLPSOL + PRIVATE + alloc.c + dlsup.c + env.c + env.h + error.c + stdc.c + stdc.h + stdout.c + stream.c + time.c + tls.c +) diff --git a/src/intopt/CMakeLists.txt b/src/intopt/CMakeLists.txt index 83fb2db..130e07d 100644 --- a/src/intopt/CMakeLists.txt +++ b/src/intopt/CMakeLists.txt @@ -13,3 +13,19 @@ target_sources(GLPK spv.c spv.h ) + +target_sources(GLPSOL + PRIVATE + cfg1.c + cfg2.c + cfg.c + cfg.h + clqcut.c + covgen.c + fpump.c + gmicut.c + gmigen.c + mirgen.c + spv.c + spv.h +) \ No newline at end of file diff --git a/src/minisat/CMakeLists.txt b/src/minisat/CMakeLists.txt index 9465504..3fc1ad7 100644 --- a/src/minisat/CMakeLists.txt +++ b/src/minisat/CMakeLists.txt @@ -3,3 +3,9 @@ target_sources(GLPK minisat.c minisat.h ) + +target_sources(GLPSOL + PRIVATE + minisat.c + minisat.h +) \ No newline at end of file diff --git a/src/misc/CMakeLists.txt b/src/misc/CMakeLists.txt index a10333f..dcce165 100644 --- a/src/misc/CMakeLists.txt +++ b/src/misc/CMakeLists.txt @@ -57,3 +57,63 @@ target_sources(GLPK wclique.c wclique.h ) + +target_sources(GLPSOL + PRIVATE + avl.c + avl.h + bignum.c + bignum.h + dimacs.c + dimacs.h + dmp.c + dmp.h + ffalg.c + ffalg.h + fp2rat.c + fvs.c + fvs.h + gcd.c + hbm.c + hbm.h + jd.c + jd.h + keller.c + keller.h + ks.c + ks.h + mc13d.c + mc13d.h + mc21a.c + mc21a.h + misc.h + mt1.c + mt1.f + mt1.h + mygmp.c + mygmp.h + okalg.c + okalg.h + qmd.c + qmd.h + relax4.c + relax4.h + rgr.c + rgr.h + rng1.c + rng.c + rng.h + round2n.c + spm.c + spm.h + str2int.c + str2num.c + strspx.c + strtrim.c + triang.c + triang.h + wclique1.c + wclique1.h + wclique.c + wclique.h +) \ No newline at end of file diff --git a/src/mpl/CMakeLists.txt b/src/mpl/CMakeLists.txt index e42f0db..5e55440 100644 --- a/src/mpl/CMakeLists.txt +++ b/src/mpl/CMakeLists.txt @@ -10,3 +10,16 @@ target_sources(GLPK mplsql.c mplsql.h ) + +target_sources(GLPSOL + PRIVATE + mpl1.c + mpl2.c + mpl3.c + mpl4.c + mpl5.c + mpl6.c + mpl.h + mplsql.c + mplsql.h +) diff --git a/src/npp/CMakeLists.txt b/src/npp/CMakeLists.txt index 2940607..30dc484 100644 --- a/src/npp/CMakeLists.txt +++ b/src/npp/CMakeLists.txt @@ -8,3 +8,14 @@ target_sources(GLPK npp6.c npp.h ) + +target_sources(GLPSOL + PRIVATE + npp1.c + npp2.c + npp3.c + npp4.c + npp5.c + npp6.c + npp.h +) diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index 6331909..ecbfeed 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -5,3 +5,10 @@ target_sources(GLPK proxy.c proxy.h ) + +target_sources(GLPSOL + PRIVATE + proxy1.c + proxy.c + proxy.h +) diff --git a/src/simplex/CMakeLists.txt b/src/simplex/CMakeLists.txt index 9b23082..8b48d97 100644 --- a/src/simplex/CMakeLists.txt +++ b/src/simplex/CMakeLists.txt @@ -20,3 +20,26 @@ target_sources(GLPK spychuzr.h spydual.c ) + +target_sources(GLPSOL + PRIVATE + simplex.h + spxat.c + spxat.h + spxchuzc.c + spxchuzc.h + spxchuzr.c + spxchuzr.h + spxlp.c + spxlp.h + spxnt.c + spxnt.h + spxprim.c + spxprob.c + spxprob.h + spychuzc.c + spychuzc.h + spychuzr.c + spychuzr.h + spydual.c +) diff --git a/src/zlib/CMakeLists.txt b/src/zlib/CMakeLists.txt index 5147e02..d43a210 100644 --- a/src/zlib/CMakeLists.txt +++ b/src/zlib/CMakeLists.txt @@ -28,3 +28,34 @@ target_sources(GLPK zutil.c zutil.h ) + +target_sources(GLPSOL + PRIVATE + adler32.c + compress.c + crc32.c + crc32.h + deflate.c + deflate.h + gzclose.c + gzguts.h + gzlib.c + gzread.c + gzwrite.c + inffast.c + inffast.h + inffixed.h + inflate.c + inflate.h + inftrees.c + inftrees.h + trees.c + trees.h + uncompr.c + zconf.h + zio.c + zio.h + zlib.h + zutil.c + zutil.h +) From 6aa1ef2281883c8b8db2884db39ba239263d9b0b Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 14:04:42 +0200 Subject: [PATCH 09/51] replaced hardcoded paths with CMake variables --- cmake/FindGMP.cmake | 2 +- src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index d9e249a..6484097 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -43,7 +43,7 @@ find_library( GMP_LIBRARY "/usr/lib64" "/usr/local/lib" "/usr/local/lib64" - "C:\\Windows\\System32" + "$ENV{SYSTEMDRIVE}/Windows/System32" ) if (GMP_LIBRARY) set(GMP_INCLUDE_DIR ../include) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6539916..9270d0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(GLPSOL) target_sources(GLPK PRIVATE glpk.h) target_sources(GLPSOL PRIVATE - ../examples/glpsol.c + ${CMAKE_SOURCE_DIR}/examples/glpsol.c PRIVATE glpk.h ) From 7afddc064b5da5076b48187d48a74f8c17ce44ab Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 14:14:22 +0200 Subject: [PATCH 10/51] removed `gmp.h`, added `find_path` to find it on the host system --- cmake/FindGMP.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 6484097..9c58ab0 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -45,9 +45,15 @@ find_library( GMP_LIBRARY "/usr/local/lib64" "$ENV{SYSTEMDRIVE}/Windows/System32" ) -if (GMP_LIBRARY) - set(GMP_INCLUDE_DIR ../include) -endif() + +find_path( GMP_INCLUDE_DIR + NAMES + "gmp.h" + PATHS + "/usr/include/" + "/usr/local/include/" + #Windows doesn't have a default collection of header files, unfortunately + ) # handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE if # all listed variables are TRUE From 0237935c9b1123b20d3424dc3856428ac52ec102 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 14:14:50 +0200 Subject: [PATCH 11/51] removed `gmp.h`, added `find_path` to find it on the host system --- include/gmp.h | 2337 ------------------------------------------------- 1 file changed, 2337 deletions(-) delete mode 100644 include/gmp.h diff --git a/include/gmp.h b/include/gmp.h deleted file mode 100644 index a46d01b..0000000 --- a/include/gmp.h +++ /dev/null @@ -1,2337 +0,0 @@ -//Windows typically doesn't have GMP.h on its PATH, so I've included it here -/* Definitions for GNU multiple precision functions. -*- mode: c -*- - -Copyright 1991, 1993-1997, 1999-2016, 2020 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of either: - - * the GNU Lesser General Public License as published by the Free - Software Foundation; either version 3 of the License, or (at your - option) any later version. - -or - - * the GNU General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any - later version. - -or both in parallel, as here. - -The GNU MP Library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received copies of the GNU General Public License and the -GNU Lesser General Public License along with the GNU MP Library. If not, -see https://www.gnu.org/licenses/. */ - -#ifndef __GMP_H__ - -#if defined (__cplusplus) -#include /* for std::istream, std::ostream, std::string */ -#include -#endif - - -/* Instantiated by configure. */ -#if ! defined (__GMP_WITHIN_CONFIGURE) -#define __GMP_HAVE_HOST_CPU_FAMILY_power 0 -#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0 -#define GMP_LIMB_BITS 64 -#define GMP_NAIL_BITS 0 -#endif -#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) -#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS) -#define GMP_NUMB_MAX GMP_NUMB_MASK -#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) - - -#ifndef __GNU_MP__ -#define __GNU_MP__ 6 - -#include /* for size_t */ -#include - -/* Instantiated by configure. */ -#if ! defined (__GMP_WITHIN_CONFIGURE) -/* #undef _LONG_LONG_LIMB */ -#define __GMP_LIBGMP_DLL 0 -#endif - - -/* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in - all other circumstances. - - When compiling objects for libgmp, __GMP_DECLSPEC is an export directive, - or when compiling for an application it's an import directive. The two - cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles - (and not defined from an application). - - __GMP_DECLSPEC_XX is similarly used for libgmpxx. __GMP_WITHIN_GMPXX - indicates when building libgmpxx, and in that case libgmpxx functions are - exports, but libgmp functions which might get called are imports. - - Libtool DLL_EXPORT define is not used. - - There's no attempt to support GMP built both static and DLL. Doing so - would mean applications would have to tell us which of the two is going - to be used when linking, and that seems very tedious and error prone if - using GMP by hand, and equally tedious from a package since autoconf and - automake don't give much help. - - __GMP_DECLSPEC is required on all documented global functions and - variables, the various internals in gmp-impl.h etc can be left unadorned. - But internals used by the test programs or speed measuring programs - should have __GMP_DECLSPEC, and certainly constants or variables must - have it or the wrong address will be resolved. - - In gcc __declspec can go at either the start or end of a prototype. - - In Microsoft C __declspec must go at the start, or after the type like - void __declspec(...) *foo()". There's no __dllexport or anything to - guard against someone foolish #defining dllexport. _export used to be - available, but no longer. - - In Borland C _export still exists, but needs to go after the type, like - "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to - make use of that. Probably more trouble than it's worth. */ - -#if defined (__GNUC__) -#define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__) -#define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__) -#endif -#if defined (_MSC_VER) || defined (__BORLANDC__) -#define __GMP_DECLSPEC_EXPORT __declspec(dllexport) -#define __GMP_DECLSPEC_IMPORT __declspec(dllimport) -#endif -#ifdef __WATCOMC__ -#define __GMP_DECLSPEC_EXPORT __export -#define __GMP_DECLSPEC_IMPORT __import -#endif -#ifdef __IBMC__ -#define __GMP_DECLSPEC_EXPORT _Export -#define __GMP_DECLSPEC_IMPORT _Import -#endif - -#if __GMP_LIBGMP_DLL -#ifdef __GMP_WITHIN_GMP -/* compiling to go into a DLL libgmp */ -#define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT -#else -/* compiling to go into an application which will link to a DLL libgmp */ -#define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT -#endif -#else -/* all other cases */ -#define __GMP_DECLSPEC -#endif - - -#ifdef __GMP_SHORT_LIMB -typedef unsigned int mp_limb_t; -typedef int mp_limb_signed_t; -#else -#ifdef _LONG_LONG_LIMB -typedef unsigned long long int mp_limb_t; -typedef long long int mp_limb_signed_t; -#else -typedef unsigned long int mp_limb_t; -typedef long int mp_limb_signed_t; -#endif -#endif -typedef unsigned long int mp_bitcnt_t; - -/* For reference, note that the name __mpz_struct gets into C++ mangled - function names, which means although the "__" suggests an internal, we - must leave this name for binary compatibility. */ -typedef struct -{ - int _mp_alloc; /* Number of *limbs* allocated and pointed - to by the _mp_d field. */ - int _mp_size; /* abs(_mp_size) is the number of limbs the - last field points to. If _mp_size is - negative this is a negative number. */ - mp_limb_t *_mp_d; /* Pointer to the limbs. */ -} __mpz_struct; - -#endif /* __GNU_MP__ */ - - -typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */ -typedef __mpz_struct mpz_t[1]; - -typedef mp_limb_t * mp_ptr; -typedef const mp_limb_t * mp_srcptr; -#if defined (_CRAY) && ! defined (_CRAYMPP) -/* plain `int' is much faster (48 bits) */ -#define __GMP_MP_SIZE_T_INT 1 -typedef int mp_size_t; -typedef int mp_exp_t; -#else -#define __GMP_MP_SIZE_T_INT 0 -typedef long int mp_size_t; -typedef long int mp_exp_t; -#endif - -typedef struct -{ - __mpz_struct _mp_num; - __mpz_struct _mp_den; -} __mpq_struct; - -typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */ -typedef __mpq_struct mpq_t[1]; - -typedef struct -{ - int _mp_prec; /* Max precision, in number of `mp_limb_t's. - Set by mpf_init and modified by - mpf_set_prec. The area pointed to by the - _mp_d field contains `prec' + 1 limbs. */ - int _mp_size; /* abs(_mp_size) is the number of limbs the - last field points to. If _mp_size is - negative this is a negative number. */ - mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ - mp_limb_t *_mp_d; /* Pointer to the limbs. */ -} __mpf_struct; - -/* typedef __mpf_struct MP_FLOAT; */ -typedef __mpf_struct mpf_t[1]; - -/* Available random number generation algorithms. */ -typedef enum -{ - GMP_RAND_ALG_DEFAULT = 0, - GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ -} gmp_randalg_t; - -/* Random state struct. */ -typedef struct -{ - mpz_t _mp_seed; /* _mp_d member points to state of the generator. */ - gmp_randalg_t _mp_alg; /* Currently unused. */ - union { - void *_mp_lc; /* Pointer to function pointers structure. */ - } _mp_algdata; -} __gmp_randstate_struct; -typedef __gmp_randstate_struct gmp_randstate_t[1]; - -/* Types for function declarations in gmp files. */ -/* ??? Should not pollute user name space with these ??? */ -typedef const __mpz_struct *mpz_srcptr; -typedef __mpz_struct *mpz_ptr; -typedef const __mpf_struct *mpf_srcptr; -typedef __mpf_struct *mpf_ptr; -typedef const __mpq_struct *mpq_srcptr; -typedef __mpq_struct *mpq_ptr; - - -#if __GMP_LIBGMP_DLL -#ifdef __GMP_WITHIN_GMPXX -/* compiling to go into a DLL libgmpxx */ -#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT -#else -/* compiling to go into a application which will link to a DLL libgmpxx */ -#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT -#endif -#else -/* all other cases */ -#define __GMP_DECLSPEC_XX -#endif - - -#ifndef __MPN -#define __MPN(x) __gmpn_##x -#endif - -/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, - defines EOF but not FILE. */ -#if defined (FILE) \ - || defined (H_STDIO) \ - || defined (_H_STDIO) /* AIX */ \ - || defined (_STDIO_H) /* glibc, Sun, SCO */ \ - || defined (_STDIO_H_) /* BSD, OSF */ \ - || defined (__STDIO_H) /* Borland */ \ - || defined (__STDIO_H__) /* IRIX */ \ - || defined (_STDIO_INCLUDED) /* HPUX */ \ - || defined (__dj_include_stdio_h_) /* DJGPP */ \ - || defined (_FILE_DEFINED) /* Microsoft */ \ - || defined (__STDIO__) /* Apple MPW MrC */ \ - || defined (_MSL_STDIO_H) /* Metrowerks */ \ - || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ - || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \ - || defined (__STDIO_LOADED) /* VMS */ \ - || defined (__DEFINED_FILE) /* musl */ -#define _GMP_H_HAVE_FILE 1 -#endif - -/* In ISO C, if a prototype involving "struct obstack *" is given without - that structure defined, then the struct is scoped down to just the - prototype, causing a conflict if it's subsequently defined for real. So - only give prototypes if we've got obstack.h. */ -#if defined (_OBSTACK_H) /* glibc */ -#define _GMP_H_HAVE_OBSTACK 1 -#endif - -/* The prototypes for gmp_vprintf etc are provided only if va_list is defined, - via an application having included . Usually va_list is a typedef - so can't be tested directly, but C99 specifies that va_start is a macro. - - will define some sort of va_list for vprintf and vfprintf, but - let's not bother trying to use that since it's not standard and since - application uses for gmp_vprintf etc will almost certainly require the - whole anyway. */ - -#ifdef va_start -#define _GMP_H_HAVE_VA_LIST 1 -#endif - -/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */ -#if defined (__GNUC__) && defined (__GNUC_MINOR__) -#define __GMP_GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else -#define __GMP_GNUC_PREREQ(maj, min) 0 -#endif - -/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically - it means a function does nothing but examine its arguments and memory - (global or via arguments) to generate a return value, but changes nothing - and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets - tune/common.c etc turn this off when trying to write timing loops. */ -#if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE) -#define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__)) -#else -#define __GMP_ATTRIBUTE_PURE -#endif - - -/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean - to "g++ -Wold-style-cast". - - Casts in "extern inline" code within an extern "C" block don't induce - these warnings, so __GMP_CAST only needs to be used on documented - macros. */ - -#ifdef __cplusplus -#define __GMP_CAST(type, expr) (static_cast (expr)) -#else -#define __GMP_CAST(type, expr) ((type) (expr)) -#endif - - -/* An empty "throw ()" means the function doesn't throw any C++ exceptions, - this can save some stack frame info in applications. - - Currently it's given only on functions which never divide-by-zero etc, - don't allocate memory, and are expected to never need to allocate memory. - This leaves open the possibility of a C++ throw from a future GMP - exceptions scheme. - - mpz_set_ui etc are omitted to leave open the lazy allocation scheme - described in doc/tasks.html. mpz_get_d etc are omitted to leave open - exceptions for float overflows. - - Note that __GMP_NOTHROW must be given on any inlines the same as on their - prototypes (for g++ at least, where they're used together). Note also - that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like - __GMP_ATTRIBUTE_PURE. */ - -#if defined (__cplusplus) -#if __cplusplus >= 201103L -#define __GMP_NOTHROW noexcept -#else -#define __GMP_NOTHROW throw () -#endif -#else -#define __GMP_NOTHROW -#endif - - -/* PORTME: What other compilers have a useful "extern inline"? "static - inline" would be an acceptable substitute if the compiler (or linker) - discards unused statics. */ - - /* gcc has __inline__ in all modes, including strict ansi. Give a prototype - for an inline too, so as to correctly specify "dllimport" on windows, in - case the function is called rather than inlined. - GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 - inline semantics, unless -fgnu89-inline is used. */ -#ifdef __GNUC__ -#if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2) \ - || (defined __GNUC_GNU_INLINE__ && defined __cplusplus) -#define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__)) -#else -#define __GMP_EXTERN_INLINE extern __inline__ -#endif -#define __GMP_INLINE_PROTOTYPES 1 -#endif - -/* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1 - strict ANSI mode. Inlining is done even when not optimizing (ie. -O0 - mode, which is the default), but an unnecessary local copy of foo is - emitted unless -O is used. "extern __inline" is accepted, but the - "extern" appears to be ignored, ie. it becomes a plain global function - but which is inlined within its file. Don't know if all old versions of - DEC C supported __inline, but as a start let's do the right thing for - current versions. */ -#ifdef __DECC -#define __GMP_EXTERN_INLINE static __inline -#endif - -/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict - ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes - place under -O. Without -O "foo" seems to be emitted whether it's used - or not, which is wasteful. "extern inline foo()" isn't useful, the - "extern" is apparently ignored, so foo is inlined if possible but also - emitted as a global, which causes multiple definition errors when - building a shared libgmp. */ -#ifdef __SCO_VERSION__ -#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \ - && ! defined (__GMP_EXTERN_INLINE) -#define __GMP_EXTERN_INLINE static inline -#endif -#endif - -/* Microsoft's C compiler accepts __inline */ -#ifdef _MSC_VER -#define __GMP_EXTERN_INLINE __inline -#endif - -/* Recent enough Sun C compilers want "inline" */ -#if defined (__SUNPRO_C) && __SUNPRO_C >= 0x560 \ - && ! defined (__GMP_EXTERN_INLINE) -#define __GMP_EXTERN_INLINE inline -#endif - -/* Somewhat older Sun C compilers want "static inline" */ -#if defined (__SUNPRO_C) && __SUNPRO_C >= 0x540 \ - && ! defined (__GMP_EXTERN_INLINE) -#define __GMP_EXTERN_INLINE static inline -#endif - - -/* C++ always has "inline" and since it's a normal feature the linker should - discard duplicate non-inlined copies, or if it doesn't then that's a - problem for everyone, not just GMP. */ -#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE) -#define __GMP_EXTERN_INLINE inline -#endif - -/* Don't do any inlining within a configure run, since if the compiler ends - up emitting copies of the code into the object file it can end up - demanding the various support routines (like mpn_popcount) for linking, - making the "alloca" test and perhaps others fail. And on hppa ia64 a - pre-release gcc 3.2 was seen not respecting the "extern" in "extern - __inline__", triggering this problem too. */ -#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE -#undef __GMP_EXTERN_INLINE -#endif - -/* By default, don't give a prototype when there's going to be an inline - version. Note in particular that Cray C++ objects to the combination of - prototype and inline. */ -#ifdef __GMP_EXTERN_INLINE -#ifndef __GMP_INLINE_PROTOTYPES -#define __GMP_INLINE_PROTOTYPES 0 -#endif -#else -#define __GMP_INLINE_PROTOTYPES 1 -#endif - - -#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x)) -#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i)) - - -/* __builtin_expect is in gcc 3.0, and not in 2.95. */ -#if __GMP_GNUC_PREREQ (3,0) -#define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1) -#define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0) -#else -#define __GMP_LIKELY(cond) (cond) -#define __GMP_UNLIKELY(cond) (cond) -#endif - -#ifdef _CRAY -#define __GMP_CRAY_Pragma(str) _Pragma (str) -#else -#define __GMP_CRAY_Pragma(str) -#endif - - -/* Allow direct user access to numerator and denominator of an mpq_t object. */ -#define mpq_numref(Q) (&((Q)->_mp_num)) -#define mpq_denref(Q) (&((Q)->_mp_den)) - - -#if defined (__cplusplus) -extern "C" { -using std::FILE; -#endif - -#define mp_set_memory_functions __gmp_set_memory_functions -__GMP_DECLSPEC void mp_set_memory_functions (void *(*) (size_t), - void *(*) (void *, size_t, size_t), - void (*) (void *, size_t)) __GMP_NOTHROW; - -#define mp_get_memory_functions __gmp_get_memory_functions -__GMP_DECLSPEC void mp_get_memory_functions (void *(**) (size_t), - void *(**) (void *, size_t, size_t), - void (**) (void *, size_t)) __GMP_NOTHROW; - -#define mp_bits_per_limb __gmp_bits_per_limb -__GMP_DECLSPEC extern const int mp_bits_per_limb; - -#define gmp_errno __gmp_errno -__GMP_DECLSPEC extern int gmp_errno; - -#define gmp_version __gmp_version -__GMP_DECLSPEC extern const char * const gmp_version; - - -/**************** Random number routines. ****************/ - -/* obsolete */ -#define gmp_randinit __gmp_randinit -__GMP_DECLSPEC void gmp_randinit (gmp_randstate_t, gmp_randalg_t, ...); - -#define gmp_randinit_default __gmp_randinit_default -__GMP_DECLSPEC void gmp_randinit_default (gmp_randstate_t); - -#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp -__GMP_DECLSPEC void gmp_randinit_lc_2exp (gmp_randstate_t, mpz_srcptr, unsigned long int, mp_bitcnt_t); - -#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size -__GMP_DECLSPEC int gmp_randinit_lc_2exp_size (gmp_randstate_t, mp_bitcnt_t); - -#define gmp_randinit_mt __gmp_randinit_mt -__GMP_DECLSPEC void gmp_randinit_mt (gmp_randstate_t); - -#define gmp_randinit_set __gmp_randinit_set -__GMP_DECLSPEC void gmp_randinit_set (gmp_randstate_t, const __gmp_randstate_struct *); - -#define gmp_randseed __gmp_randseed -__GMP_DECLSPEC void gmp_randseed (gmp_randstate_t, mpz_srcptr); - -#define gmp_randseed_ui __gmp_randseed_ui -__GMP_DECLSPEC void gmp_randseed_ui (gmp_randstate_t, unsigned long int); - -#define gmp_randclear __gmp_randclear -__GMP_DECLSPEC void gmp_randclear (gmp_randstate_t); - -#define gmp_urandomb_ui __gmp_urandomb_ui -__GMP_DECLSPEC unsigned long gmp_urandomb_ui (gmp_randstate_t, unsigned long); - -#define gmp_urandomm_ui __gmp_urandomm_ui -__GMP_DECLSPEC unsigned long gmp_urandomm_ui (gmp_randstate_t, unsigned long); - - -/**************** Formatted output routines. ****************/ - -#define gmp_asprintf __gmp_asprintf -__GMP_DECLSPEC int gmp_asprintf (char **, const char *, ...); - -#define gmp_fprintf __gmp_fprintf -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC int gmp_fprintf (FILE *, const char *, ...); -#endif - -#define gmp_obstack_printf __gmp_obstack_printf -#if defined (_GMP_H_HAVE_OBSTACK) -__GMP_DECLSPEC int gmp_obstack_printf (struct obstack *, const char *, ...); -#endif - -#define gmp_obstack_vprintf __gmp_obstack_vprintf -#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_obstack_vprintf (struct obstack *, const char *, va_list); -#endif - -#define gmp_printf __gmp_printf -__GMP_DECLSPEC int gmp_printf (const char *, ...); - -#define gmp_snprintf __gmp_snprintf -__GMP_DECLSPEC int gmp_snprintf (char *, size_t, const char *, ...); - -#define gmp_sprintf __gmp_sprintf -__GMP_DECLSPEC int gmp_sprintf (char *, const char *, ...); - -#define gmp_vasprintf __gmp_vasprintf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vasprintf (char **, const char *, va_list); -#endif - -#define gmp_vfprintf __gmp_vfprintf -#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vfprintf (FILE *, const char *, va_list); -#endif - -#define gmp_vprintf __gmp_vprintf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vprintf (const char *, va_list); -#endif - -#define gmp_vsnprintf __gmp_vsnprintf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vsnprintf (char *, size_t, const char *, va_list); -#endif - -#define gmp_vsprintf __gmp_vsprintf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vsprintf (char *, const char *, va_list); -#endif - - -/**************** Formatted input routines. ****************/ - -#define gmp_fscanf __gmp_fscanf -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC int gmp_fscanf (FILE *, const char *, ...); -#endif - -#define gmp_scanf __gmp_scanf -__GMP_DECLSPEC int gmp_scanf (const char *, ...); - -#define gmp_sscanf __gmp_sscanf -__GMP_DECLSPEC int gmp_sscanf (const char *, const char *, ...); - -#define gmp_vfscanf __gmp_vfscanf -#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vfscanf (FILE *, const char *, va_list); -#endif - -#define gmp_vscanf __gmp_vscanf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vscanf (const char *, va_list); -#endif - -#define gmp_vsscanf __gmp_vsscanf -#if defined (_GMP_H_HAVE_VA_LIST) -__GMP_DECLSPEC int gmp_vsscanf (const char *, const char *, va_list); -#endif - - -/**************** Integer (i.e. Z) routines. ****************/ - -#define _mpz_realloc __gmpz_realloc -#define mpz_realloc __gmpz_realloc -__GMP_DECLSPEC void *_mpz_realloc (mpz_ptr, mp_size_t); - -#define mpz_abs __gmpz_abs -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs) -__GMP_DECLSPEC void mpz_abs (mpz_ptr, mpz_srcptr); -#endif - -#define mpz_add __gmpz_add -__GMP_DECLSPEC void mpz_add (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_add_ui __gmpz_add_ui -__GMP_DECLSPEC void mpz_add_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_addmul __gmpz_addmul -__GMP_DECLSPEC void mpz_addmul (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_addmul_ui __gmpz_addmul_ui -__GMP_DECLSPEC void mpz_addmul_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_and __gmpz_and -__GMP_DECLSPEC void mpz_and (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_array_init __gmpz_array_init -__GMP_DECLSPEC void mpz_array_init (mpz_ptr, mp_size_t, mp_size_t); - -#define mpz_bin_ui __gmpz_bin_ui -__GMP_DECLSPEC void mpz_bin_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_bin_uiui __gmpz_bin_uiui -__GMP_DECLSPEC void mpz_bin_uiui (mpz_ptr, unsigned long int, unsigned long int); - -#define mpz_cdiv_q __gmpz_cdiv_q -__GMP_DECLSPEC void mpz_cdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp -__GMP_DECLSPEC void mpz_cdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui -__GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_cdiv_qr __gmpz_cdiv_qr -__GMP_DECLSPEC void mpz_cdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui -__GMP_DECLSPEC unsigned long int mpz_cdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_cdiv_r __gmpz_cdiv_r -__GMP_DECLSPEC void mpz_cdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp -__GMP_DECLSPEC void mpz_cdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui -__GMP_DECLSPEC unsigned long int mpz_cdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_cdiv_ui __gmpz_cdiv_ui -__GMP_DECLSPEC unsigned long int mpz_cdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; - -#define mpz_clear __gmpz_clear -__GMP_DECLSPEC void mpz_clear (mpz_ptr); - -#define mpz_clears __gmpz_clears -__GMP_DECLSPEC void mpz_clears (mpz_ptr, ...); - -#define mpz_clrbit __gmpz_clrbit -__GMP_DECLSPEC void mpz_clrbit (mpz_ptr, mp_bitcnt_t); - -#define mpz_cmp __gmpz_cmp -__GMP_DECLSPEC int mpz_cmp (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_cmp_d __gmpz_cmp_d -__GMP_DECLSPEC int mpz_cmp_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE; - -#define _mpz_cmp_si __gmpz_cmp_si -__GMP_DECLSPEC int _mpz_cmp_si (mpz_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define _mpz_cmp_ui __gmpz_cmp_ui -__GMP_DECLSPEC int _mpz_cmp_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_cmpabs __gmpz_cmpabs -__GMP_DECLSPEC int mpz_cmpabs (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_cmpabs_d __gmpz_cmpabs_d -__GMP_DECLSPEC int mpz_cmpabs_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE; - -#define mpz_cmpabs_ui __gmpz_cmpabs_ui -__GMP_DECLSPEC int mpz_cmpabs_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_com __gmpz_com -__GMP_DECLSPEC void mpz_com (mpz_ptr, mpz_srcptr); - -#define mpz_combit __gmpz_combit -__GMP_DECLSPEC void mpz_combit (mpz_ptr, mp_bitcnt_t); - -#define mpz_congruent_p __gmpz_congruent_p -__GMP_DECLSPEC int mpz_congruent_p (mpz_srcptr, mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p -__GMP_DECLSPEC int mpz_congruent_2exp_p (mpz_srcptr, mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_congruent_ui_p __gmpz_congruent_ui_p -__GMP_DECLSPEC int mpz_congruent_ui_p (mpz_srcptr, unsigned long, unsigned long) __GMP_ATTRIBUTE_PURE; - -#define mpz_divexact __gmpz_divexact -__GMP_DECLSPEC void mpz_divexact (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_divexact_ui __gmpz_divexact_ui -__GMP_DECLSPEC void mpz_divexact_ui (mpz_ptr, mpz_srcptr, unsigned long); - -#define mpz_divisible_p __gmpz_divisible_p -__GMP_DECLSPEC int mpz_divisible_p (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_divisible_ui_p __gmpz_divisible_ui_p -__GMP_DECLSPEC int mpz_divisible_ui_p (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE; - -#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p -__GMP_DECLSPEC int mpz_divisible_2exp_p (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_dump __gmpz_dump -__GMP_DECLSPEC void mpz_dump (mpz_srcptr); - -#define mpz_export __gmpz_export -__GMP_DECLSPEC void *mpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr); - -#define mpz_fac_ui __gmpz_fac_ui -__GMP_DECLSPEC void mpz_fac_ui (mpz_ptr, unsigned long int); - -#define mpz_2fac_ui __gmpz_2fac_ui -__GMP_DECLSPEC void mpz_2fac_ui (mpz_ptr, unsigned long int); - -#define mpz_mfac_uiui __gmpz_mfac_uiui -__GMP_DECLSPEC void mpz_mfac_uiui (mpz_ptr, unsigned long int, unsigned long int); - -#define mpz_primorial_ui __gmpz_primorial_ui -__GMP_DECLSPEC void mpz_primorial_ui (mpz_ptr, unsigned long int); - -#define mpz_fdiv_q __gmpz_fdiv_q -__GMP_DECLSPEC void mpz_fdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp -__GMP_DECLSPEC void mpz_fdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui -__GMP_DECLSPEC unsigned long int mpz_fdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_fdiv_qr __gmpz_fdiv_qr -__GMP_DECLSPEC void mpz_fdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui -__GMP_DECLSPEC unsigned long int mpz_fdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_fdiv_r __gmpz_fdiv_r -__GMP_DECLSPEC void mpz_fdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp -__GMP_DECLSPEC void mpz_fdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui -__GMP_DECLSPEC unsigned long int mpz_fdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_fdiv_ui __gmpz_fdiv_ui -__GMP_DECLSPEC unsigned long int mpz_fdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; - -#define mpz_fib_ui __gmpz_fib_ui -__GMP_DECLSPEC void mpz_fib_ui (mpz_ptr, unsigned long int); - -#define mpz_fib2_ui __gmpz_fib2_ui -__GMP_DECLSPEC void mpz_fib2_ui (mpz_ptr, mpz_ptr, unsigned long int); - -#define mpz_fits_sint_p __gmpz_fits_sint_p -__GMP_DECLSPEC int mpz_fits_sint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_fits_slong_p __gmpz_fits_slong_p -__GMP_DECLSPEC int mpz_fits_slong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_fits_sshort_p __gmpz_fits_sshort_p -__GMP_DECLSPEC int mpz_fits_sshort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_fits_uint_p __gmpz_fits_uint_p -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p) -__GMP_DECLSPEC int mpz_fits_uint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_fits_ulong_p __gmpz_fits_ulong_p -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p) -__GMP_DECLSPEC int mpz_fits_ulong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_fits_ushort_p __gmpz_fits_ushort_p -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p) -__GMP_DECLSPEC int mpz_fits_ushort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_gcd __gmpz_gcd -__GMP_DECLSPEC void mpz_gcd (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_gcd_ui __gmpz_gcd_ui -__GMP_DECLSPEC unsigned long int mpz_gcd_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_gcdext __gmpz_gcdext -__GMP_DECLSPEC void mpz_gcdext (mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_get_d __gmpz_get_d -__GMP_DECLSPEC double mpz_get_d (mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_get_d_2exp __gmpz_get_d_2exp -__GMP_DECLSPEC double mpz_get_d_2exp (signed long int *, mpz_srcptr); - -#define mpz_get_si __gmpz_get_si -__GMP_DECLSPEC /* signed */ long int mpz_get_si (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_get_str __gmpz_get_str -__GMP_DECLSPEC char *mpz_get_str (char *, int, mpz_srcptr); - -#define mpz_get_ui __gmpz_get_ui -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui) -__GMP_DECLSPEC unsigned long int mpz_get_ui (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_getlimbn __gmpz_getlimbn -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn) -__GMP_DECLSPEC mp_limb_t mpz_getlimbn (mpz_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_hamdist __gmpz_hamdist -__GMP_DECLSPEC mp_bitcnt_t mpz_hamdist (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_import __gmpz_import -__GMP_DECLSPEC void mpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *); - -#define mpz_init __gmpz_init -__GMP_DECLSPEC void mpz_init (mpz_ptr) __GMP_NOTHROW; - -#define mpz_init2 __gmpz_init2 -__GMP_DECLSPEC void mpz_init2 (mpz_ptr, mp_bitcnt_t); - -#define mpz_inits __gmpz_inits -__GMP_DECLSPEC void mpz_inits (mpz_ptr, ...) __GMP_NOTHROW; - -#define mpz_init_set __gmpz_init_set -__GMP_DECLSPEC void mpz_init_set (mpz_ptr, mpz_srcptr); - -#define mpz_init_set_d __gmpz_init_set_d -__GMP_DECLSPEC void mpz_init_set_d (mpz_ptr, double); - -#define mpz_init_set_si __gmpz_init_set_si -__GMP_DECLSPEC void mpz_init_set_si (mpz_ptr, signed long int); - -#define mpz_init_set_str __gmpz_init_set_str -__GMP_DECLSPEC int mpz_init_set_str (mpz_ptr, const char *, int); - -#define mpz_init_set_ui __gmpz_init_set_ui -__GMP_DECLSPEC void mpz_init_set_ui (mpz_ptr, unsigned long int); - -#define mpz_inp_raw __gmpz_inp_raw -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpz_inp_raw (mpz_ptr, FILE *); -#endif - -#define mpz_inp_str __gmpz_inp_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpz_inp_str (mpz_ptr, FILE *, int); -#endif - -#define mpz_invert __gmpz_invert -__GMP_DECLSPEC int mpz_invert (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_ior __gmpz_ior -__GMP_DECLSPEC void mpz_ior (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_jacobi __gmpz_jacobi -__GMP_DECLSPEC int mpz_jacobi (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_kronecker mpz_jacobi /* alias */ - -#define mpz_kronecker_si __gmpz_kronecker_si -__GMP_DECLSPEC int mpz_kronecker_si (mpz_srcptr, long) __GMP_ATTRIBUTE_PURE; - -#define mpz_kronecker_ui __gmpz_kronecker_ui -__GMP_DECLSPEC int mpz_kronecker_ui (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE; - -#define mpz_si_kronecker __gmpz_si_kronecker -__GMP_DECLSPEC int mpz_si_kronecker (long, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_ui_kronecker __gmpz_ui_kronecker -__GMP_DECLSPEC int mpz_ui_kronecker (unsigned long, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_lcm __gmpz_lcm -__GMP_DECLSPEC void mpz_lcm (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_lcm_ui __gmpz_lcm_ui -__GMP_DECLSPEC void mpz_lcm_ui (mpz_ptr, mpz_srcptr, unsigned long); - -#define mpz_legendre mpz_jacobi /* alias */ - -#define mpz_lucnum_ui __gmpz_lucnum_ui -__GMP_DECLSPEC void mpz_lucnum_ui (mpz_ptr, unsigned long int); - -#define mpz_lucnum2_ui __gmpz_lucnum2_ui -__GMP_DECLSPEC void mpz_lucnum2_ui (mpz_ptr, mpz_ptr, unsigned long int); - -#define mpz_millerrabin __gmpz_millerrabin -__GMP_DECLSPEC int mpz_millerrabin (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE; - -#define mpz_mod __gmpz_mod -__GMP_DECLSPEC void mpz_mod (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */ - -#define mpz_mul __gmpz_mul -__GMP_DECLSPEC void mpz_mul (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_mul_2exp __gmpz_mul_2exp -__GMP_DECLSPEC void mpz_mul_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_mul_si __gmpz_mul_si -__GMP_DECLSPEC void mpz_mul_si (mpz_ptr, mpz_srcptr, long int); - -#define mpz_mul_ui __gmpz_mul_ui -__GMP_DECLSPEC void mpz_mul_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_neg __gmpz_neg -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg) -__GMP_DECLSPEC void mpz_neg (mpz_ptr, mpz_srcptr); -#endif - -#define mpz_nextprime __gmpz_nextprime -__GMP_DECLSPEC void mpz_nextprime (mpz_ptr, mpz_srcptr); - -#define mpz_out_raw __gmpz_out_raw -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpz_out_raw (FILE *, mpz_srcptr); -#endif - -#define mpz_out_str __gmpz_out_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpz_out_str (FILE *, int, mpz_srcptr); -#endif - -#define mpz_perfect_power_p __gmpz_perfect_power_p -__GMP_DECLSPEC int mpz_perfect_power_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpz_perfect_square_p __gmpz_perfect_square_p -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p) -__GMP_DECLSPEC int mpz_perfect_square_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_popcount __gmpz_popcount -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount) -__GMP_DECLSPEC mp_bitcnt_t mpz_popcount (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_pow_ui __gmpz_pow_ui -__GMP_DECLSPEC void mpz_pow_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_powm __gmpz_powm -__GMP_DECLSPEC void mpz_powm (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr); - -#define mpz_powm_sec __gmpz_powm_sec -__GMP_DECLSPEC void mpz_powm_sec (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr); - -#define mpz_powm_ui __gmpz_powm_ui -__GMP_DECLSPEC void mpz_powm_ui (mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr); - -#define mpz_probab_prime_p __gmpz_probab_prime_p -__GMP_DECLSPEC int mpz_probab_prime_p (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE; - -#define mpz_random __gmpz_random -__GMP_DECLSPEC void mpz_random (mpz_ptr, mp_size_t); - -#define mpz_random2 __gmpz_random2 -__GMP_DECLSPEC void mpz_random2 (mpz_ptr, mp_size_t); - -#define mpz_realloc2 __gmpz_realloc2 -__GMP_DECLSPEC void mpz_realloc2 (mpz_ptr, mp_bitcnt_t); - -#define mpz_remove __gmpz_remove -__GMP_DECLSPEC mp_bitcnt_t mpz_remove (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_root __gmpz_root -__GMP_DECLSPEC int mpz_root (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_rootrem __gmpz_rootrem -__GMP_DECLSPEC void mpz_rootrem (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_rrandomb __gmpz_rrandomb -__GMP_DECLSPEC void mpz_rrandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t); - -#define mpz_scan0 __gmpz_scan0 -__GMP_DECLSPEC mp_bitcnt_t mpz_scan0 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_scan1 __gmpz_scan1 -__GMP_DECLSPEC mp_bitcnt_t mpz_scan1 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_set __gmpz_set -__GMP_DECLSPEC void mpz_set (mpz_ptr, mpz_srcptr); - -#define mpz_set_d __gmpz_set_d -__GMP_DECLSPEC void mpz_set_d (mpz_ptr, double); - -#define mpz_set_f __gmpz_set_f -__GMP_DECLSPEC void mpz_set_f (mpz_ptr, mpf_srcptr); - -#define mpz_set_q __gmpz_set_q -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q) -__GMP_DECLSPEC void mpz_set_q (mpz_ptr, mpq_srcptr); -#endif - -#define mpz_set_si __gmpz_set_si -__GMP_DECLSPEC void mpz_set_si (mpz_ptr, signed long int); - -#define mpz_set_str __gmpz_set_str -__GMP_DECLSPEC int mpz_set_str (mpz_ptr, const char *, int); - -#define mpz_set_ui __gmpz_set_ui -__GMP_DECLSPEC void mpz_set_ui (mpz_ptr, unsigned long int); - -#define mpz_setbit __gmpz_setbit -__GMP_DECLSPEC void mpz_setbit (mpz_ptr, mp_bitcnt_t); - -#define mpz_size __gmpz_size -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size) -__GMP_DECLSPEC size_t mpz_size (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpz_sizeinbase __gmpz_sizeinbase -__GMP_DECLSPEC size_t mpz_sizeinbase (mpz_srcptr, int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_sqrt __gmpz_sqrt -__GMP_DECLSPEC void mpz_sqrt (mpz_ptr, mpz_srcptr); - -#define mpz_sqrtrem __gmpz_sqrtrem -__GMP_DECLSPEC void mpz_sqrtrem (mpz_ptr, mpz_ptr, mpz_srcptr); - -#define mpz_sub __gmpz_sub -__GMP_DECLSPEC void mpz_sub (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_sub_ui __gmpz_sub_ui -__GMP_DECLSPEC void mpz_sub_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_ui_sub __gmpz_ui_sub -__GMP_DECLSPEC void mpz_ui_sub (mpz_ptr, unsigned long int, mpz_srcptr); - -#define mpz_submul __gmpz_submul -__GMP_DECLSPEC void mpz_submul (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_submul_ui __gmpz_submul_ui -__GMP_DECLSPEC void mpz_submul_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_swap __gmpz_swap -__GMP_DECLSPEC void mpz_swap (mpz_ptr, mpz_ptr) __GMP_NOTHROW; - -#define mpz_tdiv_ui __gmpz_tdiv_ui -__GMP_DECLSPEC unsigned long int mpz_tdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE; - -#define mpz_tdiv_q __gmpz_tdiv_q -__GMP_DECLSPEC void mpz_tdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp -__GMP_DECLSPEC void mpz_tdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui -__GMP_DECLSPEC unsigned long int mpz_tdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_tdiv_qr __gmpz_tdiv_qr -__GMP_DECLSPEC void mpz_tdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui -__GMP_DECLSPEC unsigned long int mpz_tdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_tdiv_r __gmpz_tdiv_r -__GMP_DECLSPEC void mpz_tdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp -__GMP_DECLSPEC void mpz_tdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t); - -#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui -__GMP_DECLSPEC unsigned long int mpz_tdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int); - -#define mpz_tstbit __gmpz_tstbit -__GMP_DECLSPEC int mpz_tstbit (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpz_ui_pow_ui __gmpz_ui_pow_ui -__GMP_DECLSPEC void mpz_ui_pow_ui (mpz_ptr, unsigned long int, unsigned long int); - -#define mpz_urandomb __gmpz_urandomb -__GMP_DECLSPEC void mpz_urandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t); - -#define mpz_urandomm __gmpz_urandomm -__GMP_DECLSPEC void mpz_urandomm (mpz_ptr, gmp_randstate_t, mpz_srcptr); - -#define mpz_xor __gmpz_xor -#define mpz_eor __gmpz_xor -__GMP_DECLSPEC void mpz_xor (mpz_ptr, mpz_srcptr, mpz_srcptr); - -#define mpz_limbs_read __gmpz_limbs_read -__GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr); - -#define mpz_limbs_write __gmpz_limbs_write -__GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t); - -#define mpz_limbs_modify __gmpz_limbs_modify -__GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t); - -#define mpz_limbs_finish __gmpz_limbs_finish -__GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t); - -#define mpz_roinit_n __gmpz_roinit_n -__GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t); - -#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} - -/**************** Rational (i.e. Q) routines. ****************/ - -#define mpq_abs __gmpq_abs -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs) -__GMP_DECLSPEC void mpq_abs (mpq_ptr, mpq_srcptr); -#endif - -#define mpq_add __gmpq_add -__GMP_DECLSPEC void mpq_add (mpq_ptr, mpq_srcptr, mpq_srcptr); - -#define mpq_canonicalize __gmpq_canonicalize -__GMP_DECLSPEC void mpq_canonicalize (mpq_ptr); - -#define mpq_clear __gmpq_clear -__GMP_DECLSPEC void mpq_clear (mpq_ptr); - -#define mpq_clears __gmpq_clears -__GMP_DECLSPEC void mpq_clears (mpq_ptr, ...); - -#define mpq_cmp __gmpq_cmp -__GMP_DECLSPEC int mpq_cmp (mpq_srcptr, mpq_srcptr) __GMP_ATTRIBUTE_PURE; - -#define _mpq_cmp_si __gmpq_cmp_si -__GMP_DECLSPEC int _mpq_cmp_si (mpq_srcptr, long, unsigned long) __GMP_ATTRIBUTE_PURE; - -#define _mpq_cmp_ui __gmpq_cmp_ui -__GMP_DECLSPEC int _mpq_cmp_ui (mpq_srcptr, unsigned long int, unsigned long int) __GMP_ATTRIBUTE_PURE; - -#define mpq_cmp_z __gmpq_cmp_z -__GMP_DECLSPEC int mpq_cmp_z (mpq_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpq_div __gmpq_div -__GMP_DECLSPEC void mpq_div (mpq_ptr, mpq_srcptr, mpq_srcptr); - -#define mpq_div_2exp __gmpq_div_2exp -__GMP_DECLSPEC void mpq_div_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t); - -#define mpq_equal __gmpq_equal -__GMP_DECLSPEC int mpq_equal (mpq_srcptr, mpq_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpq_get_num __gmpq_get_num -__GMP_DECLSPEC void mpq_get_num (mpz_ptr, mpq_srcptr); - -#define mpq_get_den __gmpq_get_den -__GMP_DECLSPEC void mpq_get_den (mpz_ptr, mpq_srcptr); - -#define mpq_get_d __gmpq_get_d -__GMP_DECLSPEC double mpq_get_d (mpq_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpq_get_str __gmpq_get_str -__GMP_DECLSPEC char *mpq_get_str (char *, int, mpq_srcptr); - -#define mpq_init __gmpq_init -__GMP_DECLSPEC void mpq_init (mpq_ptr); - -#define mpq_inits __gmpq_inits -__GMP_DECLSPEC void mpq_inits (mpq_ptr, ...); - -#define mpq_inp_str __gmpq_inp_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpq_inp_str (mpq_ptr, FILE *, int); -#endif - -#define mpq_inv __gmpq_inv -__GMP_DECLSPEC void mpq_inv (mpq_ptr, mpq_srcptr); - -#define mpq_mul __gmpq_mul -__GMP_DECLSPEC void mpq_mul (mpq_ptr, mpq_srcptr, mpq_srcptr); - -#define mpq_mul_2exp __gmpq_mul_2exp -__GMP_DECLSPEC void mpq_mul_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t); - -#define mpq_neg __gmpq_neg -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg) -__GMP_DECLSPEC void mpq_neg (mpq_ptr, mpq_srcptr); -#endif - -#define mpq_out_str __gmpq_out_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpq_out_str (FILE *, int, mpq_srcptr); -#endif - -#define mpq_set __gmpq_set -__GMP_DECLSPEC void mpq_set (mpq_ptr, mpq_srcptr); - -#define mpq_set_d __gmpq_set_d -__GMP_DECLSPEC void mpq_set_d (mpq_ptr, double); - -#define mpq_set_den __gmpq_set_den -__GMP_DECLSPEC void mpq_set_den (mpq_ptr, mpz_srcptr); - -#define mpq_set_f __gmpq_set_f -__GMP_DECLSPEC void mpq_set_f (mpq_ptr, mpf_srcptr); - -#define mpq_set_num __gmpq_set_num -__GMP_DECLSPEC void mpq_set_num (mpq_ptr, mpz_srcptr); - -#define mpq_set_si __gmpq_set_si -__GMP_DECLSPEC void mpq_set_si (mpq_ptr, signed long int, unsigned long int); - -#define mpq_set_str __gmpq_set_str -__GMP_DECLSPEC int mpq_set_str (mpq_ptr, const char *, int); - -#define mpq_set_ui __gmpq_set_ui -__GMP_DECLSPEC void mpq_set_ui (mpq_ptr, unsigned long int, unsigned long int); - -#define mpq_set_z __gmpq_set_z -__GMP_DECLSPEC void mpq_set_z (mpq_ptr, mpz_srcptr); - -#define mpq_sub __gmpq_sub -__GMP_DECLSPEC void mpq_sub (mpq_ptr, mpq_srcptr, mpq_srcptr); - -#define mpq_swap __gmpq_swap -__GMP_DECLSPEC void mpq_swap (mpq_ptr, mpq_ptr) __GMP_NOTHROW; - - -/**************** Float (i.e. F) routines. ****************/ - -#define mpf_abs __gmpf_abs -__GMP_DECLSPEC void mpf_abs (mpf_ptr, mpf_srcptr); - -#define mpf_add __gmpf_add -__GMP_DECLSPEC void mpf_add (mpf_ptr, mpf_srcptr, mpf_srcptr); - -#define mpf_add_ui __gmpf_add_ui -__GMP_DECLSPEC void mpf_add_ui (mpf_ptr, mpf_srcptr, unsigned long int); -#define mpf_ceil __gmpf_ceil -__GMP_DECLSPEC void mpf_ceil (mpf_ptr, mpf_srcptr); - -#define mpf_clear __gmpf_clear -__GMP_DECLSPEC void mpf_clear (mpf_ptr); - -#define mpf_clears __gmpf_clears -__GMP_DECLSPEC void mpf_clears (mpf_ptr, ...); - -#define mpf_cmp __gmpf_cmp -__GMP_DECLSPEC int mpf_cmp (mpf_srcptr, mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_cmp_z __gmpf_cmp_z -__GMP_DECLSPEC int mpf_cmp_z (mpf_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_cmp_d __gmpf_cmp_d -__GMP_DECLSPEC int mpf_cmp_d (mpf_srcptr, double) __GMP_ATTRIBUTE_PURE; - -#define mpf_cmp_si __gmpf_cmp_si -__GMP_DECLSPEC int mpf_cmp_si (mpf_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_cmp_ui __gmpf_cmp_ui -__GMP_DECLSPEC int mpf_cmp_ui (mpf_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_div __gmpf_div -__GMP_DECLSPEC void mpf_div (mpf_ptr, mpf_srcptr, mpf_srcptr); - -#define mpf_div_2exp __gmpf_div_2exp -__GMP_DECLSPEC void mpf_div_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t); - -#define mpf_div_ui __gmpf_div_ui -__GMP_DECLSPEC void mpf_div_ui (mpf_ptr, mpf_srcptr, unsigned long int); - -#define mpf_dump __gmpf_dump -__GMP_DECLSPEC void mpf_dump (mpf_srcptr); - -#define mpf_eq __gmpf_eq -__GMP_DECLSPEC int mpf_eq (mpf_srcptr, mpf_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_sint_p __gmpf_fits_sint_p -__GMP_DECLSPEC int mpf_fits_sint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_slong_p __gmpf_fits_slong_p -__GMP_DECLSPEC int mpf_fits_slong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_sshort_p __gmpf_fits_sshort_p -__GMP_DECLSPEC int mpf_fits_sshort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_uint_p __gmpf_fits_uint_p -__GMP_DECLSPEC int mpf_fits_uint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_ulong_p __gmpf_fits_ulong_p -__GMP_DECLSPEC int mpf_fits_ulong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_fits_ushort_p __gmpf_fits_ushort_p -__GMP_DECLSPEC int mpf_fits_ushort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_floor __gmpf_floor -__GMP_DECLSPEC void mpf_floor (mpf_ptr, mpf_srcptr); - -#define mpf_get_d __gmpf_get_d -__GMP_DECLSPEC double mpf_get_d (mpf_srcptr) __GMP_ATTRIBUTE_PURE; - -#define mpf_get_d_2exp __gmpf_get_d_2exp -__GMP_DECLSPEC double mpf_get_d_2exp (signed long int *, mpf_srcptr); - -#define mpf_get_default_prec __gmpf_get_default_prec -__GMP_DECLSPEC mp_bitcnt_t mpf_get_default_prec (void) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_get_prec __gmpf_get_prec -__GMP_DECLSPEC mp_bitcnt_t mpf_get_prec (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_get_si __gmpf_get_si -__GMP_DECLSPEC long mpf_get_si (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_get_str __gmpf_get_str -__GMP_DECLSPEC char *mpf_get_str (char *, mp_exp_t *, int, size_t, mpf_srcptr); - -#define mpf_get_ui __gmpf_get_ui -__GMP_DECLSPEC unsigned long mpf_get_ui (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_init __gmpf_init -__GMP_DECLSPEC void mpf_init (mpf_ptr); - -#define mpf_init2 __gmpf_init2 -__GMP_DECLSPEC void mpf_init2 (mpf_ptr, mp_bitcnt_t); - -#define mpf_inits __gmpf_inits -__GMP_DECLSPEC void mpf_inits (mpf_ptr, ...); - -#define mpf_init_set __gmpf_init_set -__GMP_DECLSPEC void mpf_init_set (mpf_ptr, mpf_srcptr); - -#define mpf_init_set_d __gmpf_init_set_d -__GMP_DECLSPEC void mpf_init_set_d (mpf_ptr, double); - -#define mpf_init_set_si __gmpf_init_set_si -__GMP_DECLSPEC void mpf_init_set_si (mpf_ptr, signed long int); - -#define mpf_init_set_str __gmpf_init_set_str -__GMP_DECLSPEC int mpf_init_set_str (mpf_ptr, const char *, int); - -#define mpf_init_set_ui __gmpf_init_set_ui -__GMP_DECLSPEC void mpf_init_set_ui (mpf_ptr, unsigned long int); - -#define mpf_inp_str __gmpf_inp_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpf_inp_str (mpf_ptr, FILE *, int); -#endif - -#define mpf_integer_p __gmpf_integer_p -__GMP_DECLSPEC int mpf_integer_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_mul __gmpf_mul -__GMP_DECLSPEC void mpf_mul (mpf_ptr, mpf_srcptr, mpf_srcptr); - -#define mpf_mul_2exp __gmpf_mul_2exp -__GMP_DECLSPEC void mpf_mul_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t); - -#define mpf_mul_ui __gmpf_mul_ui -__GMP_DECLSPEC void mpf_mul_ui (mpf_ptr, mpf_srcptr, unsigned long int); - -#define mpf_neg __gmpf_neg -__GMP_DECLSPEC void mpf_neg (mpf_ptr, mpf_srcptr); - -#define mpf_out_str __gmpf_out_str -#ifdef _GMP_H_HAVE_FILE -__GMP_DECLSPEC size_t mpf_out_str (FILE *, int, size_t, mpf_srcptr); -#endif - -#define mpf_pow_ui __gmpf_pow_ui -__GMP_DECLSPEC void mpf_pow_ui (mpf_ptr, mpf_srcptr, unsigned long int); - -#define mpf_random2 __gmpf_random2 -__GMP_DECLSPEC void mpf_random2 (mpf_ptr, mp_size_t, mp_exp_t); - -#define mpf_reldiff __gmpf_reldiff -__GMP_DECLSPEC void mpf_reldiff (mpf_ptr, mpf_srcptr, mpf_srcptr); - -#define mpf_set __gmpf_set -__GMP_DECLSPEC void mpf_set (mpf_ptr, mpf_srcptr); - -#define mpf_set_d __gmpf_set_d -__GMP_DECLSPEC void mpf_set_d (mpf_ptr, double); - -#define mpf_set_default_prec __gmpf_set_default_prec -__GMP_DECLSPEC void mpf_set_default_prec (mp_bitcnt_t) __GMP_NOTHROW; - -#define mpf_set_prec __gmpf_set_prec -__GMP_DECLSPEC void mpf_set_prec (mpf_ptr, mp_bitcnt_t); - -#define mpf_set_prec_raw __gmpf_set_prec_raw -__GMP_DECLSPEC void mpf_set_prec_raw (mpf_ptr, mp_bitcnt_t) __GMP_NOTHROW; - -#define mpf_set_q __gmpf_set_q -__GMP_DECLSPEC void mpf_set_q (mpf_ptr, mpq_srcptr); - -#define mpf_set_si __gmpf_set_si -__GMP_DECLSPEC void mpf_set_si (mpf_ptr, signed long int); - -#define mpf_set_str __gmpf_set_str -__GMP_DECLSPEC int mpf_set_str (mpf_ptr, const char *, int); - -#define mpf_set_ui __gmpf_set_ui -__GMP_DECLSPEC void mpf_set_ui (mpf_ptr, unsigned long int); - -#define mpf_set_z __gmpf_set_z -__GMP_DECLSPEC void mpf_set_z (mpf_ptr, mpz_srcptr); - -#define mpf_size __gmpf_size -__GMP_DECLSPEC size_t mpf_size (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpf_sqrt __gmpf_sqrt -__GMP_DECLSPEC void mpf_sqrt (mpf_ptr, mpf_srcptr); - -#define mpf_sqrt_ui __gmpf_sqrt_ui -__GMP_DECLSPEC void mpf_sqrt_ui (mpf_ptr, unsigned long int); - -#define mpf_sub __gmpf_sub -__GMP_DECLSPEC void mpf_sub (mpf_ptr, mpf_srcptr, mpf_srcptr); - -#define mpf_sub_ui __gmpf_sub_ui -__GMP_DECLSPEC void mpf_sub_ui (mpf_ptr, mpf_srcptr, unsigned long int); - -#define mpf_swap __gmpf_swap -__GMP_DECLSPEC void mpf_swap (mpf_ptr, mpf_ptr) __GMP_NOTHROW; - -#define mpf_trunc __gmpf_trunc -__GMP_DECLSPEC void mpf_trunc (mpf_ptr, mpf_srcptr); - -#define mpf_ui_div __gmpf_ui_div -__GMP_DECLSPEC void mpf_ui_div (mpf_ptr, unsigned long int, mpf_srcptr); - -#define mpf_ui_sub __gmpf_ui_sub -__GMP_DECLSPEC void mpf_ui_sub (mpf_ptr, unsigned long int, mpf_srcptr); - -#define mpf_urandomb __gmpf_urandomb -__GMP_DECLSPEC void mpf_urandomb (mpf_t, gmp_randstate_t, mp_bitcnt_t); - - -/************ Low level positive-integer (i.e. N) routines. ************/ - -/* This is ugly, but we need to make user calls reach the prefixed function. */ - -#define mpn_add __MPN(add) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add) -__GMP_DECLSPEC mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); -#endif - -#define mpn_add_1 __MPN(add_1) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1) -__GMP_DECLSPEC mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW; -#endif - -#define mpn_add_n __MPN(add_n) -__GMP_DECLSPEC mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); - -#define mpn_addmul_1 __MPN(addmul_1) -__GMP_DECLSPEC mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_cmp __MPN(cmp) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp) -__GMP_DECLSPEC int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpn_zero_p __MPN(zero_p) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_zero_p) -__GMP_DECLSPEC int mpn_zero_p (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; -#endif - -#define mpn_divexact_1 __MPN(divexact_1) -__GMP_DECLSPEC void mpn_divexact_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_divexact_by3(dst,src,size) \ - mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0)) - -#define mpn_divexact_by3c __MPN(divexact_by3c) -__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_divmod_1(qp,np,nsize,dlimb) \ - mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb) - -#define mpn_divrem __MPN(divrem) -__GMP_DECLSPEC mp_limb_t mpn_divrem (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t); - -#define mpn_divrem_1 __MPN(divrem_1) -__GMP_DECLSPEC mp_limb_t mpn_divrem_1 (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_divrem_2 __MPN(divrem_2) -__GMP_DECLSPEC mp_limb_t mpn_divrem_2 (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr); - -#define mpn_div_qr_1 __MPN(div_qr_1) -__GMP_DECLSPEC mp_limb_t mpn_div_qr_1 (mp_ptr, mp_limb_t *, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_div_qr_2 __MPN(div_qr_2) -__GMP_DECLSPEC mp_limb_t mpn_div_qr_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr); - -#define mpn_gcd __MPN(gcd) -__GMP_DECLSPEC mp_size_t mpn_gcd (mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t); - -#define mpn_gcd_11 __MPN(gcd_11) -__GMP_DECLSPEC mp_limb_t mpn_gcd_11 (mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_gcd_1 __MPN(gcd_1) -__GMP_DECLSPEC mp_limb_t mpn_gcd_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_gcdext_1 __MPN(gcdext_1) -__GMP_DECLSPEC mp_limb_t mpn_gcdext_1 (mp_limb_signed_t *, mp_limb_signed_t *, mp_limb_t, mp_limb_t); - -#define mpn_gcdext __MPN(gcdext) -__GMP_DECLSPEC mp_size_t mpn_gcdext (mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t); - -#define mpn_get_str __MPN(get_str) -__GMP_DECLSPEC size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t); - -#define mpn_hamdist __MPN(hamdist) -__GMP_DECLSPEC mp_bitcnt_t mpn_hamdist (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpn_lshift __MPN(lshift) -__GMP_DECLSPEC mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); - -#define mpn_mod_1 __MPN(mod_1) -__GMP_DECLSPEC mp_limb_t mpn_mod_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_mul __MPN(mul) -__GMP_DECLSPEC mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); - -#define mpn_mul_1 __MPN(mul_1) -__GMP_DECLSPEC mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_mul_n __MPN(mul_n) -__GMP_DECLSPEC void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); - -#define mpn_sqr __MPN(sqr) -__GMP_DECLSPEC void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t); - -#define mpn_neg __MPN(neg) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_neg) -__GMP_DECLSPEC mp_limb_t mpn_neg (mp_ptr, mp_srcptr, mp_size_t); -#endif - -#define mpn_com __MPN(com) -__GMP_DECLSPEC void mpn_com (mp_ptr, mp_srcptr, mp_size_t); - -#define mpn_perfect_square_p __MPN(perfect_square_p) -__GMP_DECLSPEC int mpn_perfect_square_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_perfect_power_p __MPN(perfect_power_p) -__GMP_DECLSPEC int mpn_perfect_power_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_popcount __MPN(popcount) -__GMP_DECLSPEC mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; - -#define mpn_pow_1 __MPN(pow_1) -__GMP_DECLSPEC mp_size_t mpn_pow_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); - -/* undocumented now, but retained here for upward compatibility */ -#define mpn_preinv_mod_1 __MPN(preinv_mod_1) -__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 (mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_random __MPN(random) -__GMP_DECLSPEC void mpn_random (mp_ptr, mp_size_t); - -#define mpn_random2 __MPN(random2) -__GMP_DECLSPEC void mpn_random2 (mp_ptr, mp_size_t); - -#define mpn_rshift __MPN(rshift) -__GMP_DECLSPEC mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); - -#define mpn_scan0 __MPN(scan0) -__GMP_DECLSPEC mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_scan1 __MPN(scan1) -__GMP_DECLSPEC mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_set_str __MPN(set_str) -__GMP_DECLSPEC mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int); - -#define mpn_sizeinbase __MPN(sizeinbase) -__GMP_DECLSPEC size_t mpn_sizeinbase (mp_srcptr, mp_size_t, int); - -#define mpn_sqrtrem __MPN(sqrtrem) -__GMP_DECLSPEC mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t); - -#define mpn_sub __MPN(sub) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub) -__GMP_DECLSPEC mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); -#endif - -#define mpn_sub_1 __MPN(sub_1) -#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1) -__GMP_DECLSPEC mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW; -#endif - -#define mpn_sub_n __MPN(sub_n) -__GMP_DECLSPEC mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); - -#define mpn_submul_1 __MPN(submul_1) -__GMP_DECLSPEC mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); - -#define mpn_tdiv_qr __MPN(tdiv_qr) -__GMP_DECLSPEC void mpn_tdiv_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); - -#define mpn_and_n __MPN(and_n) -__GMP_DECLSPEC void mpn_and_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_andn_n __MPN(andn_n) -__GMP_DECLSPEC void mpn_andn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_nand_n __MPN(nand_n) -__GMP_DECLSPEC void mpn_nand_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_ior_n __MPN(ior_n) -__GMP_DECLSPEC void mpn_ior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_iorn_n __MPN(iorn_n) -__GMP_DECLSPEC void mpn_iorn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_nior_n __MPN(nior_n) -__GMP_DECLSPEC void mpn_nior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_xor_n __MPN(xor_n) -__GMP_DECLSPEC void mpn_xor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_xnor_n __MPN(xnor_n) -__GMP_DECLSPEC void mpn_xnor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); - -#define mpn_copyi __MPN(copyi) -__GMP_DECLSPEC void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t); -#define mpn_copyd __MPN(copyd) -__GMP_DECLSPEC void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t); -#define mpn_zero __MPN(zero) -__GMP_DECLSPEC void mpn_zero (mp_ptr, mp_size_t); - -#define mpn_cnd_add_n __MPN(cnd_add_n) -__GMP_DECLSPEC mp_limb_t mpn_cnd_add_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); -#define mpn_cnd_sub_n __MPN(cnd_sub_n) -__GMP_DECLSPEC mp_limb_t mpn_cnd_sub_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); - -#define mpn_sec_add_1 __MPN(sec_add_1) -__GMP_DECLSPEC mp_limb_t mpn_sec_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); -#define mpn_sec_add_1_itch __MPN(sec_add_1_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_add_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_sec_sub_1 __MPN(sec_sub_1) -__GMP_DECLSPEC mp_limb_t mpn_sec_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr); -#define mpn_sec_sub_1_itch __MPN(sec_sub_1_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_sub_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_cnd_swap __MPN(cnd_swap) -__GMP_DECLSPEC void mpn_cnd_swap (mp_limb_t, volatile mp_limb_t *, volatile mp_limb_t *, mp_size_t); - -#define mpn_sec_mul __MPN(sec_mul) -__GMP_DECLSPEC void mpn_sec_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); -#define mpn_sec_mul_itch __MPN(sec_mul_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_mul_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_sec_sqr __MPN(sec_sqr) -__GMP_DECLSPEC void mpn_sec_sqr (mp_ptr, mp_srcptr, mp_size_t, mp_ptr); -#define mpn_sec_sqr_itch __MPN(sec_sqr_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_sqr_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_sec_powm __MPN(sec_powm) -__GMP_DECLSPEC void mpn_sec_powm (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_bitcnt_t, mp_srcptr, mp_size_t, mp_ptr); -#define mpn_sec_powm_itch __MPN(sec_powm_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_powm_itch (mp_size_t, mp_bitcnt_t, mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_sec_tabselect __MPN(sec_tabselect) -__GMP_DECLSPEC void mpn_sec_tabselect (volatile mp_limb_t *, volatile const mp_limb_t *, mp_size_t, mp_size_t, mp_size_t); - -#define mpn_sec_div_qr __MPN(sec_div_qr) -__GMP_DECLSPEC mp_limb_t mpn_sec_div_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); -#define mpn_sec_div_qr_itch __MPN(sec_div_qr_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_div_qr_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; -#define mpn_sec_div_r __MPN(sec_div_r) -__GMP_DECLSPEC void mpn_sec_div_r (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr); -#define mpn_sec_div_r_itch __MPN(sec_div_r_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_div_r_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE; - -#define mpn_sec_invert __MPN(sec_invert) -__GMP_DECLSPEC int mpn_sec_invert (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_bitcnt_t, mp_ptr); -#define mpn_sec_invert_itch __MPN(sec_invert_itch) -__GMP_DECLSPEC mp_size_t mpn_sec_invert_itch (mp_size_t) __GMP_ATTRIBUTE_PURE; - - -/**************** mpz inlines ****************/ - -/* The following are provided as inlines where possible, but always exist as - library functions too, for binary compatibility. - - Within gmp itself this inlining generally isn't relied on, since it - doesn't get done for all compilers, whereas if something is worth - inlining then it's worth arranging always. - - There are two styles of inlining here. When the same bit of code is - wanted for the inline as for the library version, then __GMP_FORCE_foo - arranges for that code to be emitted and the __GMP_EXTERN_INLINE - directive suppressed, eg. mpz_fits_uint_p. When a different bit of code - is wanted for the inline than for the library version, then - __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */ - -#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs) -__GMP_EXTERN_INLINE void -mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) -{ - if (__gmp_w != __gmp_u) - mpz_set (__gmp_w, __gmp_u); - __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size); -} -#endif - -#if GMP_NAIL_BITS == 0 -#define __GMPZ_FITS_UTYPE_P(z,maxval) \ - mp_size_t __gmp_n = z->_mp_size; \ - mp_ptr __gmp_p = z->_mp_d; \ - return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)); -#else -#define __GMPZ_FITS_UTYPE_P(z,maxval) \ - mp_size_t __gmp_n = z->_mp_size; \ - mp_ptr __gmp_p = z->_mp_d; \ - return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \ - || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS))); -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p) -#if ! defined (__GMP_FORCE_mpz_fits_uint_p) -__GMP_EXTERN_INLINE -#endif -int -mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW -{ - __GMPZ_FITS_UTYPE_P (__gmp_z, UINT_MAX); -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p) -#if ! defined (__GMP_FORCE_mpz_fits_ulong_p) -__GMP_EXTERN_INLINE -#endif -int -mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW -{ - __GMPZ_FITS_UTYPE_P (__gmp_z, ULONG_MAX); -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p) -#if ! defined (__GMP_FORCE_mpz_fits_ushort_p) -__GMP_EXTERN_INLINE -#endif -int -mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW -{ - __GMPZ_FITS_UTYPE_P (__gmp_z, USHRT_MAX); -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui) -#if ! defined (__GMP_FORCE_mpz_get_ui) -__GMP_EXTERN_INLINE -#endif -unsigned long -mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW -{ - mp_ptr __gmp_p = __gmp_z->_mp_d; - mp_size_t __gmp_n = __gmp_z->_mp_size; - mp_limb_t __gmp_l = __gmp_p[0]; - /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings - about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland - C++ 6.0 warnings about condition always true for something like - "ULONG_MAX < GMP_NUMB_MASK". */ -#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB) - /* limb==long and no nails, or limb==longlong, one limb is enough */ - return (__gmp_n != 0 ? __gmp_l : 0); -#else - /* limb==long and nails, need two limbs when available */ - __gmp_n = __GMP_ABS (__gmp_n); - if (__gmp_n <= 1) - return (__gmp_n != 0 ? __gmp_l : 0); - else - return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS); -#endif -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn) -#if ! defined (__GMP_FORCE_mpz_getlimbn) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW -{ - mp_limb_t __gmp_result = 0; - if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size))) - __gmp_result = __gmp_z->_mp_d[__gmp_n]; - return __gmp_result; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg) -__GMP_EXTERN_INLINE void -mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) -{ - if (__gmp_w != __gmp_u) - mpz_set (__gmp_w, __gmp_u); - __gmp_w->_mp_size = - __gmp_w->_mp_size; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p) -#if ! defined (__GMP_FORCE_mpz_perfect_square_p) -__GMP_EXTERN_INLINE -#endif -int -mpz_perfect_square_p (mpz_srcptr __gmp_a) -{ - mp_size_t __gmp_asize; - int __gmp_result; - - __gmp_asize = __gmp_a->_mp_size; - __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */ - if (__GMP_LIKELY (__gmp_asize > 0)) - __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize); - return __gmp_result; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount) -#if ! defined (__GMP_FORCE_mpz_popcount) -__GMP_EXTERN_INLINE -#endif -mp_bitcnt_t -mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW -{ - mp_size_t __gmp_usize; - mp_bitcnt_t __gmp_result; - - __gmp_usize = __gmp_u->_mp_size; - __gmp_result = (__gmp_usize < 0 ? ~ __GMP_CAST (mp_bitcnt_t, 0) : __GMP_CAST (mp_bitcnt_t, 0)); - if (__GMP_LIKELY (__gmp_usize > 0)) - __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize); - return __gmp_result; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q) -#if ! defined (__GMP_FORCE_mpz_set_q) -__GMP_EXTERN_INLINE -#endif -void -mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u) -{ - mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u)); -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size) -#if ! defined (__GMP_FORCE_mpz_size) -__GMP_EXTERN_INLINE -#endif -size_t -mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW -{ - return __GMP_ABS (__gmp_z->_mp_size); -} -#endif - - -/**************** mpq inlines ****************/ - -#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs) -__GMP_EXTERN_INLINE void -mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) -{ - if (__gmp_w != __gmp_u) - mpq_set (__gmp_w, __gmp_u); - __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size); -} -#endif - -#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg) -__GMP_EXTERN_INLINE void -mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) -{ - if (__gmp_w != __gmp_u) - mpq_set (__gmp_w, __gmp_u); - __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size; -} -#endif - - -/**************** mpn inlines ****************/ - -/* The comments with __GMPN_ADD_1 below apply here too. - - The test for FUNCTION returning 0 should predict well. If it's assumed - {yp,ysize} will usually have a random number of bits then the high limb - won't be full and a carry out will occur a good deal less than 50% of the - time. - - ysize==0 isn't a documented feature, but is used internally in a few - places. - - Producing cout last stops it using up a register during the main part of - the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))" - doesn't seem able to move the true and false legs of the conditional up - to the two places cout is generated. */ - -#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \ - do { \ - mp_size_t __gmp_i; \ - mp_limb_t __gmp_x; \ - \ - /* ASSERT ((ysize) >= 0); */ \ - /* ASSERT ((xsize) >= (ysize)); */ \ - /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \ - /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \ - \ - __gmp_i = (ysize); \ - if (__gmp_i != 0) \ - { \ - if (FUNCTION (wp, xp, yp, __gmp_i)) \ - { \ - do \ - { \ - if (__gmp_i >= (xsize)) \ - { \ - (cout) = 1; \ - goto __gmp_done; \ - } \ - __gmp_x = (xp)[__gmp_i]; \ - } \ - while (TEST); \ - } \ - } \ - if ((wp) != (xp)) \ - __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \ - (cout) = 0; \ - __gmp_done: \ - ; \ - } while (0) - -#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \ - __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \ - (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0)) -#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \ - __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \ - (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0)) - - -/* The use of __gmp_i indexing is designed to ensure a compile time src==dst - remains nice and clear to the compiler, so that __GMPN_COPY_REST can - disappear, and the load/add/store gets a chance to become a - read-modify-write on CISC CPUs. - - Alternatives: - - Using a pair of pointers instead of indexing would be possible, but gcc - isn't able to recognise compile-time src==dst in that case, even when the - pointers are incremented more or less together. Other compilers would - very likely have similar difficulty. - - gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or - similar to detect a compile-time src==dst. This works nicely on gcc - 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems - to be always false, for a pointer p. But the current code form seems - good enough for src==dst anyway. - - gcc on x86 as usual doesn't give particularly good flags handling for the - carry/borrow detection. It's tempting to want some multi instruction asm - blocks to help it, and this was tried, but in truth there's only a few - instructions to save and any gain is all too easily lost by register - juggling setting up for the asm. */ - -#if GMP_NAIL_BITS == 0 -#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ - do { \ - mp_size_t __gmp_i; \ - mp_limb_t __gmp_x, __gmp_r; \ - \ - /* ASSERT ((n) >= 1); */ \ - /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ - \ - __gmp_x = (src)[0]; \ - __gmp_r = __gmp_x OP (v); \ - (dst)[0] = __gmp_r; \ - if (CB (__gmp_r, __gmp_x, (v))) \ - { \ - (cout) = 1; \ - for (__gmp_i = 1; __gmp_i < (n);) \ - { \ - __gmp_x = (src)[__gmp_i]; \ - __gmp_r = __gmp_x OP 1; \ - (dst)[__gmp_i] = __gmp_r; \ - ++__gmp_i; \ - if (!CB (__gmp_r, __gmp_x, 1)) \ - { \ - if ((src) != (dst)) \ - __GMPN_COPY_REST (dst, src, n, __gmp_i); \ - (cout) = 0; \ - break; \ - } \ - } \ - } \ - else \ - { \ - if ((src) != (dst)) \ - __GMPN_COPY_REST (dst, src, n, 1); \ - (cout) = 0; \ - } \ - } while (0) -#endif - -#if GMP_NAIL_BITS >= 1 -#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ - do { \ - mp_size_t __gmp_i; \ - mp_limb_t __gmp_x, __gmp_r; \ - \ - /* ASSERT ((n) >= 1); */ \ - /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ - \ - __gmp_x = (src)[0]; \ - __gmp_r = __gmp_x OP (v); \ - (dst)[0] = __gmp_r & GMP_NUMB_MASK; \ - if (__gmp_r >> GMP_NUMB_BITS != 0) \ - { \ - (cout) = 1; \ - for (__gmp_i = 1; __gmp_i < (n);) \ - { \ - __gmp_x = (src)[__gmp_i]; \ - __gmp_r = __gmp_x OP 1; \ - (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \ - ++__gmp_i; \ - if (__gmp_r >> GMP_NUMB_BITS == 0) \ - { \ - if ((src) != (dst)) \ - __GMPN_COPY_REST (dst, src, n, __gmp_i); \ - (cout) = 0; \ - break; \ - } \ - } \ - } \ - else \ - { \ - if ((src) != (dst)) \ - __GMPN_COPY_REST (dst, src, n, 1); \ - (cout) = 0; \ - } \ - } while (0) -#endif - -#define __GMPN_ADDCB(r,x,y) ((r) < (y)) -#define __GMPN_SUBCB(r,x,y) ((x) < (y)) - -#define __GMPN_ADD_1(cout, dst, src, n, v) \ - __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB) -#define __GMPN_SUB_1(cout, dst, src, n, v) \ - __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB) - - -/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or - negative. size==0 is allowed. On random data usually only one limb will - need to be examined to get a result, so it's worth having it inline. */ -#define __GMPN_CMP(result, xp, yp, size) \ - do { \ - mp_size_t __gmp_i; \ - mp_limb_t __gmp_x, __gmp_y; \ - \ - /* ASSERT ((size) >= 0); */ \ - \ - (result) = 0; \ - __gmp_i = (size); \ - while (--__gmp_i >= 0) \ - { \ - __gmp_x = (xp)[__gmp_i]; \ - __gmp_y = (yp)[__gmp_i]; \ - if (__gmp_x != __gmp_y) \ - { \ - /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \ - (result) = (__gmp_x > __gmp_y ? 1 : -1); \ - break; \ - } \ - } \ - } while (0) - - -#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST) -#define __GMPN_COPY_REST(dst, src, size, start) \ - do { \ - /* ASSERT ((start) >= 0); */ \ - /* ASSERT ((start) <= (size)); */ \ - __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \ - } while (0) -#endif - -/* Copy {src,size} to {dst,size}, starting at "start". This is designed to - keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1, - __GMPN_ADD, etc. */ -#if ! defined (__GMPN_COPY_REST) -#define __GMPN_COPY_REST(dst, src, size, start) \ - do { \ - mp_size_t __gmp_j; \ - /* ASSERT ((size) >= 0); */ \ - /* ASSERT ((start) >= 0); */ \ - /* ASSERT ((start) <= (size)); */ \ - /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \ - __GMP_CRAY_Pragma ("_CRI ivdep"); \ - for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \ - (dst)[__gmp_j] = (src)[__gmp_j]; \ - } while (0) -#endif - -/* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use - mpn_copyi if there's a native version, and if we don't mind demanding - binary compatibility for it (on targets which use it). */ - -#if ! defined (__GMPN_COPY) -#define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0) -#endif - - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add) -#if ! defined (__GMP_FORCE_mpn_add) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) -{ - mp_limb_t __gmp_c; - __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); - return __gmp_c; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1) -#if ! defined (__GMP_FORCE_mpn_add_1) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW -{ - mp_limb_t __gmp_c; - __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); - return __gmp_c; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp) -#if ! defined (__GMP_FORCE_mpn_cmp) -__GMP_EXTERN_INLINE -#endif -int -mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW -{ - int __gmp_result; - __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size); - return __gmp_result; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_zero_p) -#if ! defined (__GMP_FORCE_mpn_zero_p) -__GMP_EXTERN_INLINE -#endif -int -mpn_zero_p (mp_srcptr __gmp_p, mp_size_t __gmp_n) __GMP_NOTHROW -{ - /* if (__GMP_LIKELY (__gmp_n > 0)) */ - do { - if (__gmp_p[--__gmp_n] != 0) - return 0; - } while (__gmp_n != 0); - return 1; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub) -#if ! defined (__GMP_FORCE_mpn_sub) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) -{ - mp_limb_t __gmp_c; - __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); - return __gmp_c; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1) -#if ! defined (__GMP_FORCE_mpn_sub_1) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW -{ - mp_limb_t __gmp_c; - __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); - return __gmp_c; -} -#endif - -#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_neg) -#if ! defined (__GMP_FORCE_mpn_neg) -__GMP_EXTERN_INLINE -#endif -mp_limb_t -mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n) -{ - while (*__gmp_up == 0) /* Low zero limbs are unchanged by negation. */ - { - *__gmp_rp = 0; - if (!--__gmp_n) /* All zero */ - return 0; - ++__gmp_up; ++__gmp_rp; - } - - *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK; - - if (--__gmp_n) /* Higher limbs get complemented. */ - mpn_com (++__gmp_rp, ++__gmp_up, __gmp_n); - - return 1; -} -#endif - -#if defined (__cplusplus) -} -#endif - - -/* Allow faster testing for negative, zero, and positive. */ -#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) -#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) -#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) - -/* When using GCC, optimize certain common comparisons. */ -#if defined (__GNUC__) && __GNUC__ >= 2 -#define mpz_cmp_ui(Z,UI) \ - (__builtin_constant_p (UI) && (UI) == 0 \ - ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) -#define mpz_cmp_si(Z,SI) \ - (__builtin_constant_p ((SI) >= 0) && (SI) >= 0 \ - ? mpz_cmp_ui (Z, __GMP_CAST (unsigned long, SI)) \ - : _mpz_cmp_si (Z,SI)) -#define mpq_cmp_ui(Q,NUI,DUI) \ - (__builtin_constant_p (NUI) && (NUI) == 0 ? mpq_sgn (Q) \ - : __builtin_constant_p ((NUI) == (DUI)) && (NUI) == (DUI) \ - ? mpz_cmp (mpq_numref (Q), mpq_denref (Q)) \ - : _mpq_cmp_ui (Q,NUI,DUI)) -#define mpq_cmp_si(q,n,d) \ - (__builtin_constant_p ((n) >= 0) && (n) >= 0 \ - ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \ - : _mpq_cmp_si (q, n, d)) -#else -#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) -#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) -#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) -#define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d) -#endif - - -/* Using "&" rather than "&&" means these can come out branch-free. Every - mpz_t has at least one limb allocated, so fetching the low limb is always - allowed. */ -#define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0])) -#define mpz_even_p(z) (! mpz_odd_p (z)) - - -/**************** C++ routines ****************/ - -#ifdef __cplusplus -__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); -__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); -__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); -__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); -__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); -__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr); -#endif - - -/* Source-level compatibility with GMP 2 and earlier. */ -#define mpn_divmod(qp,np,nsize,dp,dsize) \ - mpn_divrem (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dp, dsize) - -/* Source-level compatibility with GMP 1. */ -#define mpz_mdiv mpz_fdiv_q -#define mpz_mdivmod mpz_fdiv_qr -#define mpz_mmod mpz_fdiv_r -#define mpz_mdiv_ui mpz_fdiv_q_ui -#define mpz_mdivmod_ui(q,r,n,d) \ - (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) -#define mpz_mmod_ui(r,n,d) \ - (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) - -/* Useful synonyms, but not quite compatible with GMP 1. */ -#define mpz_div mpz_fdiv_q -#define mpz_divmod mpz_fdiv_qr -#define mpz_div_ui mpz_fdiv_q_ui -#define mpz_divmod_ui mpz_fdiv_qr_ui -#define mpz_div_2exp mpz_fdiv_q_2exp -#define mpz_mod_2exp mpz_fdiv_r_2exp - -enum -{ - GMP_ERROR_NONE = 0, - GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, - GMP_ERROR_DIVISION_BY_ZERO = 2, - GMP_ERROR_SQRT_OF_NEGATIVE = 4, - GMP_ERROR_INVALID_ARGUMENT = 8 -}; - -/* Define CC and CFLAGS which were used to build this version of GMP */ -#define __GMP_CC "x86_64-linux-gnu-gcc" -#define __GMP_CFLAGS "-g -O2 -fdebug-prefix-map=/build/gmp-xrY6Wh/gmp-6.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -O3" - -/* Major version number is the value of __GNU_MP__ too, above. */ -#define __GNU_MP_VERSION 6 -#define __GNU_MP_VERSION_MINOR 2 -#define __GNU_MP_VERSION_PATCHLEVEL 0 -#define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL) - -#define __GMP_H__ -#endif /* __GMP_H__ */ From ce26bb1a02a69054aeafd03d37a1262906bd9a73 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 15:10:47 +0200 Subject: [PATCH 12/51] fixed copy-paste code errors, added missing `GPSOL` target include dirs/link libs --- CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9b6d53..cfa9598 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,11 +101,13 @@ if(ODBC) else() message(FATAL_ERROR "Could not run 'odbc-config --cflags' or 'iodbc-config --cflags'") endif() - string(REGEX MATCH "/[^/\\]+$/gm" GMP_LIB_NAME "${GMP_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name + string(REGEX MATCH "/[^/\\]+$/gm" ODBC_LIB_NAME "${ODBC_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name if (GMP_LIB_NAME) - add_compile_definitions(ODBC_DLNAME=${GMP_LIB_NAME}) - target_link_libraries(GLPK GMP_LIBRARIES) - target_include_directories(GLPK GMP_INCLUDE_DIRS) + add_compile_definitions(ODBC_DLNAME=${ODBC_LIB_NAME}) + target_link_libraries(GLPK ODBC_LIBRARIES) + target_include_directories(GLPK ODBC_INCLUDE_DIRS) + target_link_libraries(GLPSOL ODBC_LIBRARIES) + target_include_directories(GLPSOL ODBC_INCLUDE_DIRS) else() message(FATAL_ERROR "Could not determine ODBC/iODBC library name") endif() @@ -115,7 +117,7 @@ if(ODBC) endif() include(CMakeDependentOption) -cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "SHARED_LIB" OFF) +cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "BUILD_SHARED_LIBS" OFF) if(MYSQL) find_package(MySQL) if(MYSQL_FOUND) From bd4887e975253796e256cca0c1b54773d6157ec3 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 15:43:38 +0200 Subject: [PATCH 13/51] revert GPSOL changes in favour of MUCH better upstream GPSOL changes --- src/CMakeLists.txt | 46 ----------------------------- src/amd/CMakeLists.txt | 18 ------------ src/api/CMakeLists.txt | 59 ------------------------------------- src/bflib/CMakeLists.txt | 26 ----------------- src/colamd/CMakeLists.txt | 6 ---- src/draft/CMakeLists.txt | 34 --------------------- src/env/CMakeLists.txt | 15 ---------- src/intopt/CMakeLists.txt | 16 ---------- src/minisat/CMakeLists.txt | 6 ---- src/misc/CMakeLists.txt | 60 -------------------------------------- src/mpl/CMakeLists.txt | 15 +--------- src/npp/CMakeLists.txt | 11 ------- src/proxy/CMakeLists.txt | 9 +----- src/simplex/CMakeLists.txt | 23 --------------- src/zlib/CMakeLists.txt | 31 -------------------- 15 files changed, 2 insertions(+), 373 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9270d0d..835e4e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,5 @@ add_library(GLPK) -add_executable(GLPSOL) target_sources(GLPK PRIVATE glpk.h) -target_sources(GLPSOL - PRIVATE - ${CMAKE_SOURCE_DIR}/examples/glpsol.c - PRIVATE - glpk.h -) add_subdirectory(amd) add_subdirectory(api) add_subdirectory(bflib) @@ -49,45 +42,6 @@ target_link_libraries(GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) -target_include_directories(GLPSOL - PUBLIC - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $) -target_compile_features(GLPSOL PUBLIC c_std_11) -set_target_properties(GLPSOL PROPERTIES - VERSION ${PROJECT_VERSION} - PUBLIC_HEADER glpk.h) # not sure about this one -target_link_libraries(GLPSOL - PRIVATE - $<$>:m>) -add_executable(${PROJECT_NAMESPACE}::GLPSOL ALIAS GLPSOL) -add_test( - NAME - glpsol_version - COMMAND - GLPSOL --version -) -add_test( - NAME - glpsol_solve - COMMAND - GLPSOL --mps ${CMAKE_SOURCE_DIR}/examples/murtagh.mps --max -) - # check system libs functions and headers # m::exp include(CheckSymbolExists) diff --git a/src/amd/CMakeLists.txt b/src/amd/CMakeLists.txt index 6d5105f..ae71474 100644 --- a/src/amd/CMakeLists.txt +++ b/src/amd/CMakeLists.txt @@ -14,22 +14,4 @@ target_sources(GLPK amd_post_tree.c amd_preprocess.c amd_valid.c -) - -target_sources(GLPSOL - PRIVATE - amd_1.c - amd_2.c - amd_aat.c - amd_control.c - amd_defaults.c - amd_dump.c - amd.h - amd_info.c - amd_internal.h - amd_order.c - amd_postorder.c - amd_post_tree.c - amd_preprocess.c - amd_valid.c ) \ No newline at end of file diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 6543a19..5e2f7ed 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -55,63 +55,4 @@ target_sources(GLPK wrmip.c wrprob.c wrsol.c -) - -target_sources(GLPSOL - PRIVATE - advbas.c - asnhall.c - asnlp.c - asnokalg.c - ckasn.c - ckcnf.c - cplex.c - cpp.c - cpxbas.c - graph.c - gridgen.c - intfeas1.c - maxffalg.c - maxflp.c - mcflp.c - mcfokalg.c - mcfrelax.c - minisat1.c - mpl.c - mps.c - netgen.c - npp.c - pript.c - prmip.c - prob1.c - prob2.c - prob3.c - prob4.c - prob5.c - prob.h - prrngs.c - prsol.c - rdasn.c - rdcc.c - rdcnf.c - rdipt.c - rdmaxf.c - rdmcf.c - rdmip.c - rdprob.c - rdsol.c - rmfgen.c - strong.c - topsort.c - wcliqex.c - weak.c - wrasn.c - wrcc.c - wrcnf.c - wript.c - wrmaxf.c - wrmcf.c - wrmip.c - wrprob.c - wrsol.c ) \ No newline at end of file diff --git a/src/bflib/CMakeLists.txt b/src/bflib/CMakeLists.txt index 8b415ad..0fc3c3b 100644 --- a/src/bflib/CMakeLists.txt +++ b/src/bflib/CMakeLists.txt @@ -22,30 +22,4 @@ target_sources(GLPK sgf.h sva.c sva.h -) - -target_sources(GLPSOL - PRIVATE - btf.c - btf.h - btfint.c - btfint.h - fhv.c - fhv.h - fhvint.c - fhvint.h - ifu.c - ifu.h - luf.c - luf.h - lufint.c - lufint.h - scf.c - scf.h - scfint.c - scfint.h - sgf.c - sgf.h - sva.c - sva.h ) \ No newline at end of file diff --git a/src/colamd/CMakeLists.txt b/src/colamd/CMakeLists.txt index 440a8bb..a8899d8 100644 --- a/src/colamd/CMakeLists.txt +++ b/src/colamd/CMakeLists.txt @@ -2,10 +2,4 @@ target_sources(GLPK PRIVATE colamd.c colamd.h -) - -target_sources(GLPSOL - PRIVATE - colamd.c - colamd.h ) \ No newline at end of file diff --git a/src/draft/CMakeLists.txt b/src/draft/CMakeLists.txt index d1c7c4c..ad49331 100644 --- a/src/draft/CMakeLists.txt +++ b/src/draft/CMakeLists.txt @@ -30,38 +30,4 @@ target_sources(GLPK ios.h lux.c lux.h -) - -target_sources(GLPSOL - PRIVATE - bfd.c - bfd.h - bfx.c - bfx.h - draft.h - glpapi06.c - glpapi07.c - glpapi08.c - glpapi09.c - glpapi10.c - glpapi12.c - glpapi13.c - glpios01.c - glpios02.c - glpios03.c - glpios07.c - glpios09.c - glpios11.c - glpios12.c - glpipm.c - glpipm.h - glpmat.c - glpmat.h - glpscl.c - glpssx01.c - glpssx02.c - glpssx.h - ios.h - lux.c - lux.h ) \ No newline at end of file diff --git a/src/env/CMakeLists.txt b/src/env/CMakeLists.txt index 1d3cff5..27b6f9d 100644 --- a/src/env/CMakeLists.txt +++ b/src/env/CMakeLists.txt @@ -12,18 +12,3 @@ target_sources(GLPK time.c tls.c ) - -target_sources(GLPSOL - PRIVATE - alloc.c - dlsup.c - env.c - env.h - error.c - stdc.c - stdc.h - stdout.c - stream.c - time.c - tls.c -) diff --git a/src/intopt/CMakeLists.txt b/src/intopt/CMakeLists.txt index 130e07d..b973325 100644 --- a/src/intopt/CMakeLists.txt +++ b/src/intopt/CMakeLists.txt @@ -12,20 +12,4 @@ target_sources(GLPK mirgen.c spv.c spv.h -) - -target_sources(GLPSOL - PRIVATE - cfg1.c - cfg2.c - cfg.c - cfg.h - clqcut.c - covgen.c - fpump.c - gmicut.c - gmigen.c - mirgen.c - spv.c - spv.h ) \ No newline at end of file diff --git a/src/minisat/CMakeLists.txt b/src/minisat/CMakeLists.txt index 3fc1ad7..c87d3d7 100644 --- a/src/minisat/CMakeLists.txt +++ b/src/minisat/CMakeLists.txt @@ -2,10 +2,4 @@ target_sources(GLPK PRIVATE minisat.c minisat.h -) - -target_sources(GLPSOL - PRIVATE - minisat.c - minisat.h ) \ No newline at end of file diff --git a/src/misc/CMakeLists.txt b/src/misc/CMakeLists.txt index dcce165..a3d2c35 100644 --- a/src/misc/CMakeLists.txt +++ b/src/misc/CMakeLists.txt @@ -56,64 +56,4 @@ target_sources(GLPK wclique1.h wclique.c wclique.h -) - -target_sources(GLPSOL - PRIVATE - avl.c - avl.h - bignum.c - bignum.h - dimacs.c - dimacs.h - dmp.c - dmp.h - ffalg.c - ffalg.h - fp2rat.c - fvs.c - fvs.h - gcd.c - hbm.c - hbm.h - jd.c - jd.h - keller.c - keller.h - ks.c - ks.h - mc13d.c - mc13d.h - mc21a.c - mc21a.h - misc.h - mt1.c - mt1.f - mt1.h - mygmp.c - mygmp.h - okalg.c - okalg.h - qmd.c - qmd.h - relax4.c - relax4.h - rgr.c - rgr.h - rng1.c - rng.c - rng.h - round2n.c - spm.c - spm.h - str2int.c - str2num.c - strspx.c - strtrim.c - triang.c - triang.h - wclique1.c - wclique1.h - wclique.c - wclique.h ) \ No newline at end of file diff --git a/src/mpl/CMakeLists.txt b/src/mpl/CMakeLists.txt index 5e55440..c434463 100644 --- a/src/mpl/CMakeLists.txt +++ b/src/mpl/CMakeLists.txt @@ -9,17 +9,4 @@ target_sources(GLPK mpl.h mplsql.c mplsql.h -) - -target_sources(GLPSOL - PRIVATE - mpl1.c - mpl2.c - mpl3.c - mpl4.c - mpl5.c - mpl6.c - mpl.h - mplsql.c - mplsql.h -) +) \ No newline at end of file diff --git a/src/npp/CMakeLists.txt b/src/npp/CMakeLists.txt index 30dc484..2940607 100644 --- a/src/npp/CMakeLists.txt +++ b/src/npp/CMakeLists.txt @@ -8,14 +8,3 @@ target_sources(GLPK npp6.c npp.h ) - -target_sources(GLPSOL - PRIVATE - npp1.c - npp2.c - npp3.c - npp4.c - npp5.c - npp6.c - npp.h -) diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index ecbfeed..838d3c0 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -4,11 +4,4 @@ target_sources(GLPK proxy1.c proxy.c proxy.h -) - -target_sources(GLPSOL - PRIVATE - proxy1.c - proxy.c - proxy.h -) +) \ No newline at end of file diff --git a/src/simplex/CMakeLists.txt b/src/simplex/CMakeLists.txt index 8b48d97..9b23082 100644 --- a/src/simplex/CMakeLists.txt +++ b/src/simplex/CMakeLists.txt @@ -20,26 +20,3 @@ target_sources(GLPK spychuzr.h spydual.c ) - -target_sources(GLPSOL - PRIVATE - simplex.h - spxat.c - spxat.h - spxchuzc.c - spxchuzc.h - spxchuzr.c - spxchuzr.h - spxlp.c - spxlp.h - spxnt.c - spxnt.h - spxprim.c - spxprob.c - spxprob.h - spychuzc.c - spychuzc.h - spychuzr.c - spychuzr.h - spydual.c -) diff --git a/src/zlib/CMakeLists.txt b/src/zlib/CMakeLists.txt index d43a210..5147e02 100644 --- a/src/zlib/CMakeLists.txt +++ b/src/zlib/CMakeLists.txt @@ -28,34 +28,3 @@ target_sources(GLPK zutil.c zutil.h ) - -target_sources(GLPSOL - PRIVATE - adler32.c - compress.c - crc32.c - crc32.h - deflate.c - deflate.h - gzclose.c - gzguts.h - gzlib.c - gzread.c - gzwrite.c - inffast.c - inffast.h - inffixed.h - inflate.c - inflate.h - inftrees.c - inftrees.h - trees.c - trees.h - uncompr.c - zconf.h - zio.c - zio.h - zlib.h - zutil.c - zutil.h -) From f384b7b71490818f236b464c7a3557117a89a4d9 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 15:43:59 +0200 Subject: [PATCH 14/51] added GPSOL smoke tests --- examples/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index aaf479d..e3e1433 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,6 +15,20 @@ add_executable(${PROJECT_NAMESPACE}::glpsol ALIAS glpsol) install(TARGETS glpsol EXPORT ${PROJECT_NAME}Targets) +# GPSOL tests +add_test( + NAME + glpsol_version + COMMAND + GLPSOL --version +) +add_test( + NAME + glpsol_solve + COMMAND + GLPSOL --mps ${CMAKE_SOURCE_DIR}/examples/murtagh.mps --max +) + if(NOT BUILD_EXAMPLES) return() endif() From ab690784d059cea9bf518568387628dd5fb18b42 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:09:19 +0200 Subject: [PATCH 15/51] switched to dune-common version of `FindGMP.cmake` --- CMakeLists.txt | 7 +- cmake/FindGMP.cmake | 230 ++++++++++++++----- cmake/dune-common-gplv2.md | 443 +++++++++++++++++++++++++++++++++++++ 3 files changed, 617 insertions(+), 63 deletions(-) create mode 100644 cmake/dune-common-gplv2.md diff --git a/CMakeLists.txt b/CMakeLists.txt index cfa9598..7ab6c8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,12 +71,12 @@ option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) -option(WITH_GMP "use GNU MP bignum library" OFF) +include(CMakeDependentOption) +cmake_dependent_option(WITH_GMP "use GNU MP bignum library" ON "NOT MSVC" OFF) if(WITH_GMP) find_package(GMP) if(GMP_FOUND) - target_include_directories(GLPK GMP_INCLUDE_DIRS) - target_link_libraries(GLPK GMP_LIBRARIES) + target_link_libraries(GLPK GMP::gmp) else() message(FATAL_ERROR "gmp.h/libgmp not found") endif() @@ -116,7 +116,6 @@ if(ODBC) endif() endif() -include(CMakeDependentOption) cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "BUILD_SHARED_LIBS" OFF) if(MYSQL) find_package(MySQL) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 9c58ab0..8f1ef9a 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -1,67 +1,179 @@ -# Adapted from https://gist.github.com/RenatoUtsch/1623340 +#### LICENSE #### +# This file is copied from the Dune project (http://dune-project.org/), specifically the dune-project/dune-common git +# repo (https://github.com/dune-project/dune-common), and is thus licensed under a modified GPLv2 license. A copy of +# that license can be found in this directory as `dune-common-gplv2.md`. # -# - Try to find GMP. -# Once done this will define: -# GMP_FOUND - If false, do not try to use GMP. -# GMP_INCLUDE_DIRS - Where to find GMP.h, etc. -# GMP_LIBRARIES - The libraries to link against. -# GMP_VERSION_STRING - Version in a string of GMP. +# The original file can be found at https://github.com/dune-project/dune-common/blob/v2.8.0/cmake/modules/FindGMP.cmake # -# Created by RenatoUtsch based on eAthena implementation. +# Copyright holders: +# ================== # -# Please note that this module only supports Windows and Linux officially, but -# should work on all UNIX-like operational systems too. -# -#============================================================================= -# original gist (https://gist.github.com/RenatoUtsch/1623340) Copyright 2012 RenatoUtsch -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_library( GMP_LIBRARY - NAMES - "libgmp" - "libgmp-10" - "libgmp.so" - "libgmp.so.10" - "libgmp-10.so" - "libgmp.dll" - "libgmp-10.dll" - "libgmp.dylib" - "libgmp-10.dylib" - PATHS - "/lib" - "/lib64" - "/usr/lib" - "/usr/lib64" - "/usr/local/lib" - "/usr/local/lib64" - "$ENV{SYSTEMDRIVE}/Windows/System32" - ) +# 2015--2017 Marco Agnese +# 2015 Martin Alkämper +# 2003--2019 Peter Bastian +# 2004--2020 Markus Blatt +# 2013 Andreas Buhr +# 2020--2021 Samuel Burbulla +# 2011--2020 Ansgar Burchardt +# 2004--2005 Adrian Burri +# 2014 Benjamin Bykowski (may appear in the logs as "Convex Function") +# 2014 Marco Cecchetti +# 2018 Matthew Collins +# 2006--2021 Andreas Dedner +# 2019--2021 Nils-Arne Dreier +# 2003 Marc Droske +# 2003--2021 Christian Engwer +# 2004--2020 Jorrit Fahlke +# 2016 Thomas Fetzer +# 2008--2017 Bernd Flemisch +# 2013--2014 Christoph Gersbacher +# 2017--2020 Janick Gerstenberger +# 2015 Stefan Girke +# 2005--2021 Carsten Gräser +# 2015--2017 Felix Gruber +# 2010--2021 Christoph Grüninger +# 2006 Bernhard Haasdonk +# 2015--2018 Claus-Justus Heine +# 2015--2020 René Heß +# 2017--2019 Stephan Hilb +# 2017--2021 Lasse Hinrichsen +# 2012--2013 Olaf Ippisch +# 2020 Patrick Jaap +# 2020 Liam Keegan +# 2013--2021 Dominic Kempf +# 2009 Leonard Kern +# 2017--2018 Daniel Kienle +# 2013 Torbjörn Klatt +# 2003--2021 Robert Klöfkorn +# 2017--2021 Timo Koch +# 2005--2007 Sreejith Pulloor Kuttanikkad +# 2012--2016 Arne Morten Kvarving +# 2010--2014 Andreas Lauser +# 2016--2019 Tobias Leibner +# 2015 Lars Lubkoll +# 2012--2017 Tobias Malkmus +# 2007--2011 Sven Marnach +# 2010--2017 Rene Milk +# 2019--2020 Felix Müller +# 2011--2019 Steffen Müthing +# 2018 Lisa Julia Nebel +# 2003--2006 Thimo Neubauer +# 2011 Rebecca Neumann +# 2008--2018 Martin Nolte +# 2014 Andreas Nüßing +# 2004--2005 Mario Ohlberger +# 2019--2020 Santiago Ospina De Los Rios +# 2014 Steffen Persvold +# 2008--2017 Elias Pipping +# 2021 Joscha Podlesny +# 2011 Dan Popovic +# 2017--2021 Simon Praetorius +# 2009 Atgeirr Rasmussen +# 2017--2020 Lukas Renelt +# 2006--2014 Uli Sack +# 2003--2020 Oliver Sander +# 2006 Klaus Schneider +# 2004 Roland Schulz +# 2015 Nicolas Schwenck +# 2016 Linus Seelinger +# 2009--2014 Bård Skaflestad +# 2019 Henrik Stolzmann +# 2012 Matthias Wohlmuth +# 2011--2016 Jonathan Youett + +#[=======================================================================[.rst: +FindGMP +------- + +Find the GNU MULTI-Precision Bignum (GMP) library +and the corresponding C++ bindings GMPxx. + +This module searches for both libraries and only considers the package +found if both can be located. It then defines separate targets for the C +and the C++ library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``GMP::gmp`` + Library target of the C library. +``GMP::gmpxx`` + Library target of the C++ library, which also links to the C library. + +Result Variables +^^^^^^^^^^^^^^^^ -find_path( GMP_INCLUDE_DIR - NAMES - "gmp.h" - PATHS - "/usr/include/" - "/usr/local/include/" - #Windows doesn't have a default collection of header files, unfortunately +This will define the following variables: + +``GMP_FOUND`` + True if the GMP library, the GMPxx headers and + the GMPxx library were found. + +Cache Variables +^^^^^^^^^^^^^^^ + +You may set the following variables to modify the behaviour of +this module: + +``GMP_INCLUDE_DIR`` + The directory containing ``gmp.h``. +``GMP_LIB`` + The path to the gmp library. +``GMPXX_INCLUDE_DIR`` + The directory containing ``gmpxx.h``. +``GMPXX_LIB`` + The path to the gmpxx library. + +#]=======================================================================] + +# Add a feature summary for this package +include(FeatureSummary) +set_package_properties(GMP PROPERTIES + DESCRIPTION "GNU multi-precision library" + URL "https://gmplib.org" ) -# handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE if -# all listed variables are TRUE -include( FindPackageHandleStandardArgs ) -find_package_handle_standard_args( GMP DEFAULT_MSG - REQUIRED_VARS GMP_LIBRARY GMP_INCLUDE_DIR ) +# Try finding the package with pkg-config +find_package(PkgConfig QUIET) +pkg_check_modules(PKG QUIET gmp gmpxx) + +# Try to locate the libraries and their headers, using pkg-config hints +find_path(GMP_INCLUDE_DIR gmp.h HINTS ${PKG_gmp_INCLUDEDIR}) +find_library(GMP_LIB gmp HINTS ${PKG_gmp_LIBDIR}) + +find_path(GMPXX_INCLUDE_DIR gmpxx.h HINTS ${PKG_gmpxx_INCLUDEDIR}) +find_library(GMPXX_LIB gmpxx HINTS ${PKG_gmpxx_LIBDIR}) + +# Remove these variables from cache inspector +mark_as_advanced(GMP_INCLUDE_DIR GMP_LIB GMPXX_INCLUDE_DIR GMPXX_LIB) + +# Report if package was found +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GMP + DEFAULT_MSG + GMPXX_LIB GMPXX_INCLUDE_DIR GMP_INCLUDE_DIR GMP_LIB + ) -set( GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR} ) -set( GMP_LIBRARIES ${GMP_LIBRARY} ) +# Set targets +if(GMP_FOUND) + # C library + if(NOT TARGET GMP::gmp) + add_library(GMP::gmp UNKNOWN IMPORTED) + set_target_properties(GMP::gmp PROPERTIES + IMPORTED_LOCATION ${GMP_LIB} + INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR} + ) + endif() -mark_as_advanced( GMP_INCLUDE_DIR GMP_LIBRARY ) + # C++ library, which requires a link to the C library + if(NOT TARGET GMP::gmpxx) + add_library(GMP::gmpxx UNKNOWN IMPORTED) + set_target_properties(GMP::gmpxx PROPERTIES + IMPORTED_LOCATION ${GMPXX_LIB} + INTERFACE_INCLUDE_DIRECTORIES ${GMPXX_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES GMP::gmp + ) + endif() +endif() \ No newline at end of file diff --git a/cmake/dune-common-gplv2.md b/cmake/dune-common-gplv2.md new file mode 100644 index 0000000..6d1a984 --- /dev/null +++ b/cmake/dune-common-gplv2.md @@ -0,0 +1,443 @@ +Copyright holders: +================== + +2015--2017 Marco Agnese +2015 Martin Alkämper +2003--2019 Peter Bastian +2004--2020 Markus Blatt +2013 Andreas Buhr +2020--2021 Samuel Burbulla +2011--2020 Ansgar Burchardt +2004--2005 Adrian Burri +2014 Benjamin Bykowski (may appear in the logs as "Convex Function") +2014 Marco Cecchetti +2018 Matthew Collins +2006--2021 Andreas Dedner +2019--2021 Nils-Arne Dreier +2003 Marc Droske +2003--2021 Christian Engwer +2004--2020 Jorrit Fahlke +2016 Thomas Fetzer +2008--2017 Bernd Flemisch +2013--2014 Christoph Gersbacher +2017--2020 Janick Gerstenberger +2015 Stefan Girke +2005--2021 Carsten Gräser +2015--2017 Felix Gruber +2010--2021 Christoph Grüninger +2006 Bernhard Haasdonk +2015--2018 Claus-Justus Heine +2015--2020 René Heß +2017--2019 Stephan Hilb +2017--2021 Lasse Hinrichsen +2012--2013 Olaf Ippisch +2020 Patrick Jaap +2020 Liam Keegan +2013--2021 Dominic Kempf +2009 Leonard Kern +2017--2018 Daniel Kienle +2013 Torbjörn Klatt +2003--2021 Robert Klöfkorn +2017--2021 Timo Koch +2005--2007 Sreejith Pulloor Kuttanikkad +2012--2016 Arne Morten Kvarving +2010--2014 Andreas Lauser +2016--2019 Tobias Leibner +2015 Lars Lubkoll +2012--2017 Tobias Malkmus +2007--2011 Sven Marnach +2010--2017 Rene Milk +2019--2020 Felix Müller +2011--2019 Steffen Müthing +2018 Lisa Julia Nebel +2003--2006 Thimo Neubauer +2011 Rebecca Neumann +2008--2018 Martin Nolte +2014 Andreas Nüßing +2004--2005 Mario Ohlberger +2019--2020 Santiago Ospina De Los Rios +2014 Steffen Persvold +2008--2017 Elias Pipping +2021 Joscha Podlesny +2011 Dan Popovic +2017--2021 Simon Praetorius +2009 Atgeirr Rasmussen +2017--2020 Lukas Renelt +2006--2014 Uli Sack +2003--2020 Oliver Sander +2006 Klaus Schneider +2004 Roland Schulz +2015 Nicolas Schwenck +2016 Linus Seelinger +2009--2014 Bård Skaflestad +2019 Henrik Stolzmann +2012 Matthias Wohlmuth +2011--2016 Jonathan Youett + +This Licence does not cover the header files taken from the +[pybind11 project][pybind11] which are included here +(`dune/python/pybind11`) together with their own [licence file][pybind11Licence]. + +The DUNE library and headers are licensed under version 2 of the GNU +General Public License (see below), with a special exception for +linking and compiling against DUNE, the so-called "runtime exception." +The license is intended to be similar to the GNU Lesser General +Public License, which by itself isn't suitable for a template library. + +The exact wording of the exception reads as follows: + +As a special exception, you may use the DUNE source files as part +of a software library or application without restriction. +Specifically, if other files instantiate templates or use macros or +inline functions from one or more of the DUNE source files, or you +compile one or more of the DUNE source files and link them with +other files to produce an executable, this does not by itself cause +the resulting executable to be covered by the GNU General Public +License. This exception does not however invalidate any other +reasons why the executable file might be covered by the GNU General +Public License. + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains + a notice placed by the copyright holder saying it may be distributed + under the terms of this General Public License. The "Program", below, + refers to any such program or work, and a "work based on the Program" + means either the Program or any derivative work under copyright law: + that is to say, a work containing the Program or a portion of it, + either verbatim or with modifications and/or translated into another + language. (Hereinafter, translation is included without limitation in + the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's + source code as you receive it, in any medium, provided that you + conspicuously and appropriately publish on each copy an appropriate + copyright notice and disclaimer of warranty; keep intact all the + notices that refer to this License and to the absence of any warranty; + and give any other recipients of the Program a copy of this License + along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion + of it, thus forming a work based on the Program, and copy and + distribute such modifications or work under the terms of Section 1 + above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, + under Section 2) in object code or executable form under the terms of + Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program + except as expressly provided under this License. Any attempt + otherwise to copy, modify, sublicense or distribute the Program is + void, and will automatically terminate your rights under this License. + However, parties who have received copies, or rights, from you under + this License will not have their licenses terminated so long as such + parties remain in full compliance. + +5. You are not required to accept this License, since you have not + signed it. However, nothing else grants you permission to modify or + distribute the Program or its derivative works. These actions are + prohibited by law if you do not accept this License. Therefore, by + modifying or distributing the Program (or any work based on the + Program), you indicate your acceptance of this License to do so, and + all its terms and conditions for copying, distributing or modifying + the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the + Program), the recipient automatically receives a license from the + original licensor to copy, distribute or modify the Program subject to + these terms and conditions. You may not impose any further + restrictions on the recipients' exercise of the rights granted herein. + You are not responsible for enforcing compliance by third parties to + this License. + +7. If, as a consequence of a court judgment or allegation of patent + infringement or for any other reason (not limited to patent issues), + conditions are imposed on you (whether by court order, agreement or + otherwise) that contradict the conditions of this License, they do not + excuse you from the conditions of this License. If you cannot + distribute so as to satisfy simultaneously your obligations under this + License and any other pertinent obligations, then as a consequence you + may not distribute the Program at all. For example, if a patent + license would not permit royalty-free redistribution of the Program by + all those who receive copies directly or indirectly through you, then + the only way you could satisfy both it and this License would be to + refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in + certain countries either by patents or by copyrighted interfaces, the + original copyright holder who places the Program under this License + may add an explicit geographical distribution limitation excluding + those countries, so that distribution is permitted only in or among + countries not thus excluded. In such case, this License incorporates + the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions + of the General Public License from time to time. Such new versions will + be similar in spirit to the present version, but may differ in detail to + address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free + programs whose distribution conditions are different, write to the author + to ask for permission. For software which is copyrighted by the Free + Software Foundation, write to the Free Software Foundation; we sometimes + make exceptions for this. Our decision will be guided by the two goals + of preserving the free status of all derivatives of our free software and + of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY + FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN + OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES + PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED + OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS + TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE + PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, + REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING + WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR + REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, + INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING + OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED + TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY + YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER + PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + +[pybind11]: https://github.com/pybind/pybind11 +[pybind11Licence]: https://github.com/pybind/pybind11/blob/master/LICENSE \ No newline at end of file From ca65817e6b49727e777337a0375983449c073387 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:10:01 +0200 Subject: [PATCH 16/51] added default `OFF` for CMake option `ODBC` --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ab6c8a..5ba2fd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ if(WITH_GMP) endif() endif() -option(ODBC "enable MathProg ODBC support") +option(ODBC "enable MathProg ODBC support" OFF) if(ODBC) include(FindODBC) if(ODBC_FOUND) From bbab4a76186a14d39850144ba97a87866aad1a25 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:10:18 +0200 Subject: [PATCH 17/51] removed lingering GPSOL change --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ba2fd8..269e61c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,8 +106,6 @@ if(ODBC) add_compile_definitions(ODBC_DLNAME=${ODBC_LIB_NAME}) target_link_libraries(GLPK ODBC_LIBRARIES) target_include_directories(GLPK ODBC_INCLUDE_DIRS) - target_link_libraries(GLPSOL ODBC_LIBRARIES) - target_include_directories(GLPSOL ODBC_INCLUDE_DIRS) else() message(FATAL_ERROR "Could not determine ODBC/iODBC library name") endif() From 3120d1039d99c0f98e9c36b510f7e6daac4e63b2 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:11:13 +0200 Subject: [PATCH 18/51] clarified TLS comment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 269e61c..b70697c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ if(IS_REENTRANT) elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") set(TLS "__declspec(thread)") else() - set(TLS "_Thread_local") # default to C11 standard, may break some builds if TLS isn't supported + set(TLS "_Thread_local") # default to C11 standard, may break some builds if thread local storage isn't supported endif() add_compile_definitions(TLS=${TLS}) endif() \ No newline at end of file From 99bfeb66100e808eb94645a4d32a1ee055528c1e Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:12:54 +0200 Subject: [PATCH 19/51] another GLPSOL change reverted --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 835e4e9..a80c08d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,6 @@ if(NOT HAVE_EXP) check_symbol_exists(exp "math.h" HAVE_EXP) if(HAVE_EXP) target_link_libraries(GLPK PRIVATE m) - target_link_libraries(GLPSOL PRIVATE m) else() message(FATAL_ERROR "exp function not found") endif() From 0ba82afbd5a449c351c22a63dd448954d23f2f74 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:20:27 +0200 Subject: [PATCH 20/51] Fixed `target_link_libraries` not working on *nix --- CMakeLists.txt | 3 ++- cmake/FindGMP.cmake | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b70697c..fb36f11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,8 @@ cmake_dependent_option(WITH_GMP "use GNU MP bignum library" ON "NOT MSVC" OFF) if(WITH_GMP) find_package(GMP) if(GMP_FOUND) - target_link_libraries(GLPK GMP::gmp) + target_link_libraries(GLPK GMP_LIBRARIES) + target_include_directories(GLPK GMP_INCLUDE_DIRS) else() message(FATAL_ERROR "gmp.h/libgmp not found") endif() diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 8f1ef9a..6b7ae41 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -167,6 +167,12 @@ if(GMP_FOUND) ) endif() + set( GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR} ) + set( GMP_LIBRARIES ${GMP_LIB} ) + + mark_as_advanced( GMP_INCLUDE_DIR GMP_LIB ) + + # C++ library, which requires a link to the C library if(NOT TARGET GMP::gmpxx) add_library(GMP::gmpxx UNKNOWN IMPORTED) @@ -176,4 +182,10 @@ if(GMP_FOUND) INTERFACE_LINK_LIBRARIES GMP::gmp ) endif() + + set( GMPXX_INCLUDE_DIRS ${GMPXX_INCLUDE_DIR} ) + set( GMPXX_LIBRARIES ${GMPXX_LIB} ) + + mark_as_advanced( GMPXX_INCLUDE_DIR GMPXX_LIB ) + endif() \ No newline at end of file From baa2fbbd434bfa43bccdf4cc1740a51923dbc5de Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:20:27 +0200 Subject: [PATCH 21/51] Fixed `target_link_libraries` not working on *nix --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b70697c..b6cfb02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ cmake_dependent_option(WITH_GMP "use GNU MP bignum library" ON "NOT MSVC" OFF) if(WITH_GMP) find_package(GMP) if(GMP_FOUND) - target_link_libraries(GLPK GMP::gmp) + target_link_libraries(GLPK PRIVATE GMP::gmp) else() message(FATAL_ERROR "gmp.h/libgmp not found") endif() From ba81562aa22c01998899e8a1a94e9b44edde572a Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 16:33:25 +0200 Subject: [PATCH 22/51] removed unneeded math lib check --- src/CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a80c08d..e38f35e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,19 +43,6 @@ target_link_libraries(GLPK add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) # check system libs functions and headers -# m::exp -include(CheckSymbolExists) -check_symbol_exists(exp "math.h" HAVE_EXP) -if(NOT HAVE_EXP) - unset(HAVE_EXP CACHE) - list(APPEND CMAKE_REQUIRED_LIBRARIES "m") - check_symbol_exists(exp "math.h" HAVE_EXP) - if(HAVE_EXP) - target_link_libraries(GLPK PRIVATE m) - else() - message(FATAL_ERROR "exp function not found") - endif() -endif() # sys/time.h if(NOT MSVC) From 41a7ffd3fc35434a8dad4c0e5093d7c3ca63b301 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 20:10:42 +0200 Subject: [PATCH 23/51] remove unused CMake vars --- cmake/FindGMP.cmake | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 6b7ae41..a5ead13 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -167,12 +167,6 @@ if(GMP_FOUND) ) endif() - set( GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR} ) - set( GMP_LIBRARIES ${GMP_LIB} ) - - mark_as_advanced( GMP_INCLUDE_DIR GMP_LIB ) - - # C++ library, which requires a link to the C library if(NOT TARGET GMP::gmpxx) add_library(GMP::gmpxx UNKNOWN IMPORTED) @@ -183,9 +177,4 @@ if(GMP_FOUND) ) endif() - set( GMPXX_INCLUDE_DIRS ${GMPXX_INCLUDE_DIR} ) - set( GMPXX_LIBRARIES ${GMPXX_LIB} ) - - mark_as_advanced( GMPXX_INCLUDE_DIR GMPXX_LIB ) - endif() \ No newline at end of file From 0ea516f271743ed2b2c375487016fe969f1011aa Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 20:16:23 +0200 Subject: [PATCH 24/51] use `find_package(ODBC)` rather than `include(FindODBC)` for more consistent code --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6cfb02..f70327d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ endif() option(ODBC "enable MathProg ODBC support" OFF) if(ODBC) - include(FindODBC) + find_package(ODBC) if(ODBC_FOUND) if(ODBC_CONFIG) execute_process(COMMAND "${ODBC_CONFIG} --cflags" From 81d93e0cdab6e18c1c8a386a532f353112533efd Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 20:18:39 +0200 Subject: [PATCH 25/51] escape parentheses --- cmake/FindMySQL.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake/FindMySQL.cmake b/cmake/FindMySQL.cmake index 4f68d69..0d5df4b 100644 --- a/cmake/FindMySQL.cmake +++ b/cmake/FindMySQL.cmake @@ -27,13 +27,13 @@ if( WIN32 ) find_path( MYSQL_INCLUDE_DIR NAMES "mysql.h" PATHS "$ENV{PROGRAMFILES}/MySQL/*/include" - "$ENV{PROGRAMFILES(x86)}/MySQL/*/include" + "$ENV{PROGRAMFILES\(x86\)}/MySQL/*/include" "$ENV{SYSTEMDRIVE}/MySQL/*/include" ) find_library( MYSQL_LIBRARY NAMES "mysqlclient" "mysqlclient_r" PATHS "$ENV{PROGRAMFILES}/MySQL/*/lib" - "$ENV{PROGRAMFILES(x86)}/MySQL/*/lib" + "$ENV{PROGRAMFILES\(x86\)}/MySQL/*/lib" "$ENV{SYSTEMDRIVE}/MySQL/*/lib" ) else() find_path( MYSQL_INCLUDE_DIR @@ -54,8 +54,6 @@ else() "/usr/mysql/lib64/mysql" ) endif() - - if( MYSQL_INCLUDE_DIR AND EXISTS "${MYSQL_INCLUDE_DIRS}/mysql_version.h" ) file( STRINGS "${MYSQL_INCLUDE_DIRS}/mysql_version.h" MYSQL_VERSION_H REGEX "^#define[ \t]+MYSQL_SERVER_VERSION[ \t]+\"[^\"]+\".*$" ) From aa620131e6541df2c07d6811c6d7c10bc860e8d2 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 20:32:55 +0200 Subject: [PATCH 26/51] fixed misleading comment - DLLs are supported, but default off on Windows --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f70327d..2993ad9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ if(UNIX) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR}) endforeach() else() - # Currently Only support static build for windows + # Default to static build for non-unix option(BUILD_SHARED_LIBS "Build shared libraries (.dll)." OFF) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) From 7d4476f7caf4c9ef8ed718ffbb13999e1a6bdd22 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 20:34:10 +0200 Subject: [PATCH 27/51] allow `WITH_GMP` on Windows, but default to `OFF` --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2993ad9..a2f3aab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,8 +71,11 @@ option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) -include(CMakeDependentOption) -cmake_dependent_option(WITH_GMP "use GNU MP bignum library" ON "NOT MSVC" OFF) +if (UNIX) + option(WITH_GMP "use GNU MP bignum library" ON) +else() # default to off on non-unix + option(WITH_GMP "use GNU MP bignum library" OFF) +endif() if(WITH_GMP) find_package(GMP) if(GMP_FOUND) @@ -114,6 +117,7 @@ if(ODBC) endif() endif() +include(CMakeDependentOption) cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "BUILD_SHARED_LIBS" OFF) if(MYSQL) find_package(MySQL) From 5958194179692b848e28a3536166af075c79f549 Mon Sep 17 00:00:00 2001 From: Two4 Date: Thu, 11 Nov 2021 21:04:48 +0200 Subject: [PATCH 28/51] fixed `gettimeofday` function check --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e38f35e..827a1f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,12 +52,12 @@ if(NOT MSVC) add_compile_definitions(HAVE_SYS_TIME_H=1) endif() endif() - -# gettimeofday function -include(CheckFunctionExists) -check_function_exists(gettimeofday, HAVE_GETTIMEOFDAY_FUNC) -if(HAVE_GETTIMEOFDAY_FUNC) - add_compile_definitions(HAVE_GETTIMEOFDAY=1) +if(HAS_TIME_H) + include(CheckSymbolExists) + check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY_FUNC) + if(HAVE_GETTIMEOFDAY_FUNC) + add_compile_definitions(HAVE_GETTIMEOFDAY=1) + endif() endif() #add_subdirectory(tests) From e78e02b513ac24223d9efe5d4b56b998a9d53123 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:14:10 +0200 Subject: [PATCH 29/51] added libm link for examples (some were failing) --- cmake/c.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/c.cmake b/cmake/c.cmake index 47d1d1e..51e2057 100644 --- a/cmake/c.cmake +++ b/cmake/c.cmake @@ -83,7 +83,8 @@ function(add_c_example FILE_NAME) target_include_directories(${EXAMPLE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${EXAMPLE_NAME} PRIVATE c_std_11) target_link_libraries(${EXAMPLE_NAME} PRIVATE - ${PROJECT_NAMESPACE}::GLPK) + ${PROJECT_NAMESPACE}::GLPK + $<$>:m>) include(GNUInstallDirs) install(TARGETS ${EXAMPLE_NAME}) From d76dbf8cf457af9d0f58bf67f6c993e4a8900b6e Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:15:46 +0200 Subject: [PATCH 30/51] moved example directory target enumeration to its own function --- cmake/examples.cmake | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cmake/examples.cmake diff --git a/cmake/examples.cmake b/cmake/examples.cmake new file mode 100644 index 0000000..dc116c4 --- /dev/null +++ b/cmake/examples.cmake @@ -0,0 +1,59 @@ +function(add_example_folder EXAMPLE_SRC_DIRECTORY) + #get example dir relative to source root + string(REPLACE ${CMAKE_SOURCE_DIR} "" EXAMPLE_RELATIVE_DIR ${EXAMPLE_SRC_DIRECTORY}) + #remove any leading slash + string(REGEX REPLACE "^[/|\\]+" "" EXAMPLE_RELATIVE_DIR ${EXAMPLE_RELATIVE_DIR}) + + # change runtime output dir for examples + # multi-cfg builds + foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES) + string(TOUPPER ${OutputConfig} OUTPUTCONFIG) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${EXAMPLE_RELATIVE_DIR}) + endforeach() + # single-cfg builds + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXAMPLE_RELATIVE_DIR}) + + # compile example executables + file(GLOB C_SRCS "*.c" LIST_DIRECTORIES false) + list(FILTER C_SRCS EXCLUDE REGEX ".*/glpsol.c") # project non-example executable target + list(FILTER C_SRCS EXCLUDE REGEX ".*/netgen.c") # no license + foreach(FILE_NAME IN LISTS C_SRCS) + if(NOT (IS_DIRECTORY ${FILE_NAME})) # `LIST_DIRECTORIES false` not reliable + add_c_test(${FILE_NAME}) + endif() + endforeach() + + # copy example data to build output folder + # using `configure_file` creates a data dependence + # i.e. changes in the example data will reflect in the output folder + file(GLOB EXAMPLE_DATA_FILES "*" LIST_DIRECTORIES false) + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.[c|h]") # remove *.c and *.h files + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.am") # remove automake files + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.bat") # remove batch files + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/CMakeLists\\.txt") # remove CMakeLists.txt + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile") # remove Makefiles + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile.in") # remove Makefile templates + list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/build\\.sh") # remove build scripts + foreach(EXAMPLE_DATA_FILE IN LISTS EXAMPLE_DATA_FILES) + get_filename_component(EXAMPLE_DATA_NAME ${EXAMPLE_DATA_FILE} NAME) + if(NOT (IS_DIRECTORY ${EXAMPLE_DATA_FILE})) # `LIST_DIRECTORIES false` not reliable + configure_file( + ${EXAMPLE_DATA_FILE} + ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXAMPLE_RELATIVE_DIR}/${EXAMPLE_DATA_NAME} + COPYONLY + ) + endif() + endforeach() +endfunction() + +# https://stackoverflow.com/questions/7787823/cmake-how-to-get-the-name-of-all-subdirectories-of-a-directory +MACRO(SUBDIRLIST result curdir) + FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) + SET(dirlist "") + FOREACH(child ${children}) + IF(IS_DIRECTORY ${curdir}/${child}) + LIST(APPEND dirlist ${child}) + ENDIF() + ENDFOREACH() + SET(${result} ${dirlist}) +ENDMACRO() \ No newline at end of file From 6fd2ccd87a5bb46ea1a3c0a5f1e26f5c1326ea0e Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:17:02 +0200 Subject: [PATCH 31/51] changed `add_compile_definitions` to `target_compile_definitions` as the definition weren't found during compilation --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2f3aab..5044e91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,7 @@ if(ODBC) endif() string(REGEX MATCH "/[^/\\]+$/gm" ODBC_LIB_NAME "${ODBC_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name if (GMP_LIB_NAME) - add_compile_definitions(ODBC_DLNAME=${ODBC_LIB_NAME}) + target_compile_definitions(GLPK PUBLIC ODBC_DLNAME=${ODBC_LIB_NAME}) target_link_libraries(GLPK ODBC_LIBRARIES) target_include_directories(GLPK ODBC_INCLUDE_DIRS) else() @@ -142,5 +142,5 @@ if(IS_REENTRANT) else() set(TLS "_Thread_local") # default to C11 standard, may break some builds if thread local storage isn't supported endif() - add_compile_definitions(TLS=${TLS}) + target_compile_definitions(GLPK PUBLIC TLS=${TLS}) endif() \ No newline at end of file From 04b909c7a98bf58d12cc6ff48e8c8f0e81cd7041 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:17:56 +0200 Subject: [PATCH 32/51] fixed gpsol smoke tests --- examples/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e3e1433..c7ad455 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,15 +18,15 @@ install(TARGETS glpsol # GPSOL tests add_test( NAME - glpsol_version + glpsol_version COMMAND - GLPSOL --version + glpsol --version ) add_test( NAME - glpsol_solve + glpsol_solve COMMAND - GLPSOL --mps ${CMAKE_SOURCE_DIR}/examples/murtagh.mps --max + glpsol --mps ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/examples/murtagh.mps --max ) if(NOT BUILD_EXAMPLES) From 14fa8e6ba69d3e454cf5717ef62b9c0e86f86de8 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:19:54 +0200 Subject: [PATCH 33/51] used new `add_example_folder` function to add all tests/examples and example data --- examples/CMakeLists.txt | 12 +++-- examples/cplex/CMakeLists.txt | 3 ++ examples/csv/CMakeLists.txt | 3 ++ examples/dbf/CMakeLists.txt | 3 ++ examples/oldapi/CMakeLists.txt | 6 +++ examples/pbn/CMakeLists.txt | 3 ++ examples/sql/CMakeLists.txt | 3 ++ examples/threads/CMakeLists.txt | 26 +++++++++ examples/tsp/CMakeLists.txt | 94 +++++++++++++++++++++++++++++++++ 9 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 examples/cplex/CMakeLists.txt create mode 100644 examples/csv/CMakeLists.txt create mode 100644 examples/dbf/CMakeLists.txt create mode 100644 examples/oldapi/CMakeLists.txt create mode 100644 examples/pbn/CMakeLists.txt create mode 100644 examples/sql/CMakeLists.txt create mode 100644 examples/threads/CMakeLists.txt create mode 100644 examples/tsp/CMakeLists.txt diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c7ad455..c1e66d9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -33,9 +33,11 @@ if(NOT BUILD_EXAMPLES) return() endif() -file(GLOB C_SRCS "*.c") -list(FILTER C_SRCS EXCLUDE REGEX ".*/glpsol.c") # need input file -list(FILTER C_SRCS EXCLUDE REGEX ".*/netgen.c") # no license -foreach(FILE_NAME IN LISTS C_SRCS) - add_c_example(${FILE_NAME}) +include(examples) +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) + +# get example subdirectories and add them +SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) +foreach(SUBDIR IN LISTS SUBDIRS) + add_subdirectory(${SUBDIR}) endforeach() \ No newline at end of file diff --git a/examples/cplex/CMakeLists.txt b/examples/cplex/CMakeLists.txt new file mode 100644 index 0000000..1782437 --- /dev/null +++ b/examples/cplex/CMakeLists.txt @@ -0,0 +1,3 @@ +include(examples) + +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/csv/CMakeLists.txt b/examples/csv/CMakeLists.txt new file mode 100644 index 0000000..1782437 --- /dev/null +++ b/examples/csv/CMakeLists.txt @@ -0,0 +1,3 @@ +include(examples) + +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/dbf/CMakeLists.txt b/examples/dbf/CMakeLists.txt new file mode 100644 index 0000000..1782437 --- /dev/null +++ b/examples/dbf/CMakeLists.txt @@ -0,0 +1,3 @@ +include(examples) + +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/oldapi/CMakeLists.txt b/examples/oldapi/CMakeLists.txt new file mode 100644 index 0000000..ac3514f --- /dev/null +++ b/examples/oldapi/CMakeLists.txt @@ -0,0 +1,6 @@ +#The examples in this directory do not compile due to a code error at examples/oldapi/lpx.c:1502 +return() + +#include(examples) +# +#add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/pbn/CMakeLists.txt b/examples/pbn/CMakeLists.txt new file mode 100644 index 0000000..1782437 --- /dev/null +++ b/examples/pbn/CMakeLists.txt @@ -0,0 +1,3 @@ +include(examples) + +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/sql/CMakeLists.txt b/examples/sql/CMakeLists.txt new file mode 100644 index 0000000..1782437 --- /dev/null +++ b/examples/sql/CMakeLists.txt @@ -0,0 +1,3 @@ +include(examples) + +add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/examples/threads/CMakeLists.txt b/examples/threads/CMakeLists.txt new file mode 100644 index 0000000..5684f6e --- /dev/null +++ b/examples/threads/CMakeLists.txt @@ -0,0 +1,26 @@ +if(APPLE) + set(CMAKE_INSTALL_RPATH + "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN") +endif() + +add_executable(multiseed multiseed.c) +target_compile_features(multiseed PRIVATE c_std_11) +if (UNIX) + find_package(Threads REQUIRED) +endif() +target_link_libraries(multiseed PRIVATE + ${PROJECT_NAMESPACE}::GLPK + $<$>:m> + $<$>:Threads::Threads> +) + +install(TARGETS multiseed) + +add_test( + NAME + c_examples_multiseed + COMMAND + multiseed clustering.mod 20 +) \ No newline at end of file diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt new file mode 100644 index 0000000..6c69b30 --- /dev/null +++ b/examples/tsp/CMakeLists.txt @@ -0,0 +1,94 @@ +# I've probably done this whole thing completely wrong, but it works + +if(APPLE) + set(CMAKE_INSTALL_RPATH + "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN") +endif() + +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + +#get dir relative to source root +string(REPLACE ${CMAKE_SOURCE_DIR} "" RELATIVE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +#remove any leading slash +string(REGEX REPLACE "^[/|\\]+" "" RELATIVE_DIR ${RELATIVE_DIR}) +# multi-cfg builds +foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES) + string(TOUPPER ${OutputConfig} OUTPUTCONFIG) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) +endforeach() +# single-cfg builds +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) + +file(GLOB TEST_FILES "*.c" LIST_DIRECTORIES false) +list(FILTER TEST_FILES EXCLUDE REGEX ".*/main.c") # executable +list(FILTER TEST_FILES EXCLUDE REGEX ".*/tsplib.c") # dependent +foreach(TEST_FILE IN LISTS TEST_FILES) + if(NOT (IS_DIRECTORY ${TEST_FILE})) # `LIST_DIRECTORIES false` not reliable + get_filename_component(TEST_TARGET_NAME ${TEST_FILE} NAME_WE) + add_library(${TEST_TARGET_NAME} ${TEST_FILE}) + target_include_directories(${TEST_TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + target_compile_features(${TEST_TARGET_NAME} PRIVATE c_std_11) + target_link_libraries(${TEST_TARGET_NAME} PRIVATE + $<$>:m>) + add_library(${PROJECT_NAMESPACE}::${TEST_TARGET_NAME} ALIAS ${TEST_TARGET_NAME}) + install(TARGETS ${TEST_TARGET_NAME}) + set_target_properties(${TEST_TARGET_NAME} PROPERTIES PREFIX "") + endif() +endforeach() + +add_library(tsplib tsplib.c) +target_include_directories(tsplib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(tsplib PRIVATE c_std_11) +target_link_libraries(tsplib PRIVATE + ${PROJECT_NAMESPACE}::GLPK + ${PROJECT_NAMESPACE}::misc + $<$>:m>) +add_library(${PROJECT_NAMESPACE}::tsplib ALIAS tsplib) +install(TARGETS tsplib) + +set_target_properties(tsplib PROPERTIES PREFIX "") + +add_executable(tspsol main.c) +target_include_directories(tspsol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(tspsol PRIVATE c_std_11) +target_link_libraries(tspsol PRIVATE + ${PROJECT_NAMESPACE}::GLPK + ${PROJECT_NAMESPACE}::tsplib + ${PROJECT_NAMESPACE}::mincut + ${PROJECT_NAMESPACE}::maxflow + $<$>:m>) + +include(GNUInstallDirs) +install(TARGETS tspsol) + +# copy example data to build output folder +# using `configure_file` creates a data dependence +# i.e. changes in the example data will reflect in the output folder +file(GLOB EXAMPLE_DATA_FILES "*" LIST_DIRECTORIES false) +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.[c|h]") # remove *.c and *.h files +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.am") # remove automake files +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.bat") # remove batch files +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/CMakeLists\\.txt") # remove CMakeLists.txt +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile") # remove Makefiles +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile.in") # remove Makefile templates +list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/build\\.sh") # remove build scripts +foreach(EXAMPLE_DATA_FILE IN LISTS EXAMPLE_DATA_FILES) + get_filename_component(EXAMPLE_DATA_NAME ${EXAMPLE_DATA_FILE} NAME) + if(NOT (IS_DIRECTORY ${EXAMPLE_DATA_FILE})) # `LIST_DIRECTORIES false` not reliable + configure_file( + ${EXAMPLE_DATA_FILE} + ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RELATIVE_DIR}/${EXAMPLE_DATA_NAME} + COPYONLY + ) + endif() +endforeach() + +if(BUILD_TESTING) + add_test(NAME tspsol_solve COMMAND tspsol "${CMAKE_BINARY_DIR}/${RELATIVE_DIR}/sample.tsp") +endif() \ No newline at end of file From b6d6153f0264cebf177286a1a54cbee4c09d9e3a Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 17:27:14 +0200 Subject: [PATCH 34/51] copy library to test output dirs to allow tests to run --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 827a1f0..26990a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,6 +42,11 @@ target_link_libraries(GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) +add_custom_command(TARGET GLPK POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/examples/cplex/$" + COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/examples/tsp/$" + ) + # check system libs functions and headers # sys/time.h From 1461d815345086d5b101a53b8c10c627c1424e9e Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 20:25:53 +0200 Subject: [PATCH 35/51] CMake will now always try to find libgmp, but will warn and continue if not found --- CMakeLists.txt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5044e91..1a7e970 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,18 +71,11 @@ option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) -if (UNIX) - option(WITH_GMP "use GNU MP bignum library" ON) -else() # default to off on non-unix - option(WITH_GMP "use GNU MP bignum library" OFF) -endif() -if(WITH_GMP) - find_package(GMP) - if(GMP_FOUND) - target_link_libraries(GLPK PRIVATE GMP::gmp) - else() - message(FATAL_ERROR "gmp.h/libgmp not found") - endif() +find_package(GMP) +if(GMP_FOUND) + target_link_libraries(GLPK PRIVATE GMP::gmp) +else() + message(WARNING "gmp.h/libgmp not found") endif() option(ODBC "enable MathProg ODBC support" OFF) From 24be42f00b310f05c4b9fa577141307e43fdbdbc Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:09:46 +0200 Subject: [PATCH 36/51] remove cplex example due to missing external deps --- examples/cplex/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/cplex/CMakeLists.txt b/examples/cplex/CMakeLists.txt index 1782437..2491c64 100644 --- a/examples/cplex/CMakeLists.txt +++ b/examples/cplex/CMakeLists.txt @@ -1,3 +1,6 @@ -include(examples) +# This example folder requires external dependencies to build (see README) +return() -add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file +#include(examples) +# +#add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file From 2cdd7f7cdba57027a9727746678fcaed25dcbd1f Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:10:27 +0200 Subject: [PATCH 37/51] include src folder for examples --- examples/tsp/CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt index 6c69b30..56a2466 100644 --- a/examples/tsp/CMakeLists.txt +++ b/examples/tsp/CMakeLists.txt @@ -32,7 +32,11 @@ foreach(TEST_FILE IN LISTS TEST_FILES) if(NOT (IS_DIRECTORY ${TEST_FILE})) # `LIST_DIRECTORIES false` not reliable get_filename_component(TEST_TARGET_NAME ${TEST_FILE} NAME_WE) add_library(${TEST_TARGET_NAME} ${TEST_FILE}) - target_include_directories(${TEST_TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + target_include_directories( + ${TEST_TARGET_NAME} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_SOURCE_DIR}/src + ) target_compile_features(${TEST_TARGET_NAME} PRIVATE c_std_11) target_link_libraries(${TEST_TARGET_NAME} PRIVATE $<$>:m>) @@ -43,7 +47,11 @@ foreach(TEST_FILE IN LISTS TEST_FILES) endforeach() add_library(tsplib tsplib.c) -target_include_directories(tsplib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories( + tsplib + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_SOURCE_DIR}/src +) target_compile_features(tsplib PRIVATE c_std_11) target_link_libraries(tsplib PRIVATE ${PROJECT_NAMESPACE}::GLPK @@ -55,7 +63,11 @@ install(TARGETS tsplib) set_target_properties(tsplib PROPERTIES PREFIX "") add_executable(tspsol main.c) -target_include_directories(tspsol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories( + tspsol + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_SOURCE_DIR}/src +) target_compile_features(tspsol PRIVATE c_std_11) target_link_libraries(tspsol PRIVATE ${PROJECT_NAMESPACE}::GLPK From 49f3d0acc5debfb24f902e6dd28327646433b659 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:11:44 +0200 Subject: [PATCH 38/51] added missing define for MSVC builds, restructured system checks --- src/CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26990a3..3decf57 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,12 +49,20 @@ add_custom_command(TARGET GLPK POST_BUILD # check system libs functions and headers -# sys/time.h -if(NOT MSVC) +# define if windows environment +if(MSVC) + target_compile_definitions(GLPK PUBLIC __WOE__=1) +else() + # sys/time.h include(CheckIncludeFile) check_include_file(sys/time.h HAS_TIME_H) if(HAS_TIME_H) - add_compile_definitions(HAVE_SYS_TIME_H=1) + target_compile_definitions(GLPK PUBLIC HAVE_SYS_TIME_H=1) + include(CheckSymbolExists) + check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY_FUNC) + if(HAVE_GETTIMEOFDAY_FUNC) + target_compile_definitions(GLPK PUBLIC HAVE_GETTIMEOFDAY=1) + endif() endif() endif() if(HAS_TIME_H) From 8c27127affb04d8fbb2309230dd92f13d9f90337 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:12:49 +0200 Subject: [PATCH 39/51] missing libgmp now gives dev warning instead of warning --- src/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3decf57..1dc74b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,12 +65,14 @@ else() endif() endif() endif() -if(HAS_TIME_H) - include(CheckSymbolExists) - check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY_FUNC) - if(HAVE_GETTIMEOFDAY_FUNC) - add_compile_definitions(HAVE_GETTIMEOFDAY=1) - endif() + +# libgmp/gmp.h +find_package(GMP) +if(GMP_FOUND) + target_link_libraries(GLPK PRIVATE GMP::gmp) + target_compile_definitions(GLPK PUBLIC HAVE_GMP=1) +else() + message(AUTHOR_WARNING "gmp.h/libgmp not found") endif() #add_subdirectory(tests) From 2d6693b984a4230f5b4c4779289e54c74253f987 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:13:42 +0200 Subject: [PATCH 40/51] libgmp check no longer depends on option, moved to `src/CmakeLists.txt` --- CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a7e970..e4b7666 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,13 +71,6 @@ option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) -find_package(GMP) -if(GMP_FOUND) - target_link_libraries(GLPK PRIVATE GMP::gmp) -else() - message(WARNING "gmp.h/libgmp not found") -endif() - option(ODBC "enable MathProg ODBC support" OFF) if(ODBC) find_package(ODBC) From a7884001218c9d7916c57e326e54cf5219a3b6df Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:27:05 +0200 Subject: [PATCH 41/51] added missing GLPK dependence for tsp examples --- examples/tsp/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt index 56a2466..66ff1fc 100644 --- a/examples/tsp/CMakeLists.txt +++ b/examples/tsp/CMakeLists.txt @@ -35,10 +35,10 @@ foreach(TEST_FILE IN LISTS TEST_FILES) target_include_directories( ${TEST_TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC ${CMAKE_SOURCE_DIR}/src ) target_compile_features(${TEST_TARGET_NAME} PRIVATE c_std_11) target_link_libraries(${TEST_TARGET_NAME} PRIVATE + ${PROJECT_NAMESPACE}::GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::${TEST_TARGET_NAME} ALIAS ${TEST_TARGET_NAME}) install(TARGETS ${TEST_TARGET_NAME}) @@ -50,7 +50,6 @@ add_library(tsplib tsplib.c) target_include_directories( tsplib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC ${CMAKE_SOURCE_DIR}/src ) target_compile_features(tsplib PRIVATE c_std_11) target_link_libraries(tsplib PRIVATE @@ -66,7 +65,6 @@ add_executable(tspsol main.c) target_include_directories( tspsol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC ${CMAKE_SOURCE_DIR}/src ) target_compile_features(tspsol PRIVATE c_std_11) target_link_libraries(tspsol PRIVATE From aaf643aa1fa93d49e02413089440e7c1e06e3849 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:40:44 +0200 Subject: [PATCH 42/51] comment out problematic `#include ` (non-standard, deprecated) --- examples/threads/multiseed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/threads/multiseed.c b/examples/threads/multiseed.c index eb5d215..e9cf60d 100644 --- a/examples/threads/multiseed.c +++ b/examples/threads/multiseed.c @@ -32,7 +32,7 @@ */ #include -#include +//#include //deprecated, use stdlib.h #include #include #include From c70e08e1fa6e4b82835fdf008222ae4a2e2eae15 Mon Sep 17 00:00:00 2001 From: Two4 Date: Fri, 12 Nov 2021 21:57:58 +0200 Subject: [PATCH 43/51] changed dependencies around for tsp libs --- examples/tsp/CMakeLists.txt | 63 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt index 66ff1fc..bdc3350 100644 --- a/examples/tsp/CMakeLists.txt +++ b/examples/tsp/CMakeLists.txt @@ -25,26 +25,49 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) -file(GLOB TEST_FILES "*.c" LIST_DIRECTORIES false) -list(FILTER TEST_FILES EXCLUDE REGEX ".*/main.c") # executable -list(FILTER TEST_FILES EXCLUDE REGEX ".*/tsplib.c") # dependent -foreach(TEST_FILE IN LISTS TEST_FILES) - if(NOT (IS_DIRECTORY ${TEST_FILE})) # `LIST_DIRECTORIES false` not reliable - get_filename_component(TEST_TARGET_NAME ${TEST_FILE} NAME_WE) - add_library(${TEST_TARGET_NAME} ${TEST_FILE}) - target_include_directories( - ${TEST_TARGET_NAME} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ) - target_compile_features(${TEST_TARGET_NAME} PRIVATE c_std_11) - target_link_libraries(${TEST_TARGET_NAME} PRIVATE - ${PROJECT_NAMESPACE}::GLPK - $<$>:m>) - add_library(${PROJECT_NAMESPACE}::${TEST_TARGET_NAME} ALIAS ${TEST_TARGET_NAME}) - install(TARGETS ${TEST_TARGET_NAME}) - set_target_properties(${TEST_TARGET_NAME} PROPERTIES PREFIX "") - endif() -endforeach() +add_library(maxflow maxflow.c) +target_include_directories( + maxflow + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) +target_compile_features(maxflow PRIVATE c_std_11) +target_link_libraries(maxflow PRIVATE + ${PROJECT_NAMESPACE}::GLPK + $<$>:m>) +add_library(${PROJECT_NAMESPACE}::maxflow ALIAS maxflow) +install(TARGETS maxflow) + +set_target_properties(maxflow PROPERTIES PREFIX "") + +add_library(mincut mincut.c) +target_include_directories( + mincut + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) +target_compile_features(mincut PRIVATE c_std_11) +target_link_libraries(mincut PRIVATE + ${PROJECT_NAMESPACE}::GLPK + ${PROJECT_NAMESPACE}::maxflow + $<$>:m>) +add_library(${PROJECT_NAMESPACE}::mincut ALIAS mincut) +install(TARGETS mincut) + +set_target_properties(mincut PROPERTIES PREFIX "") + + +add_library(misc misc.c) +target_include_directories( + misc + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) +target_compile_features(misc PRIVATE c_std_11) +target_link_libraries(misc PRIVATE + ${PROJECT_NAMESPACE}::GLPK + $<$>:m>) +add_library(${PROJECT_NAMESPACE}::misc ALIAS misc) +install(TARGETS misc) + +set_target_properties(misc PROPERTIES PREFIX "") add_library(tsplib tsplib.c) target_include_directories( From 24ef74bd410d018c903352708f081126f77b3123 Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 09:10:34 +0200 Subject: [PATCH 44/51] try to fix failing test on XCode --- examples/tsp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt index bdc3350..f122808 100644 --- a/examples/tsp/CMakeLists.txt +++ b/examples/tsp/CMakeLists.txt @@ -123,5 +123,5 @@ foreach(EXAMPLE_DATA_FILE IN LISTS EXAMPLE_DATA_FILES) endforeach() if(BUILD_TESTING) - add_test(NAME tspsol_solve COMMAND tspsol "${CMAKE_BINARY_DIR}/${RELATIVE_DIR}/sample.tsp") + add_test(NAME tspsol_solve COMMAND tspsol "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RELATIVE_DIR}/sample.tsp") endif() \ No newline at end of file From 140306507ff384bdbfa99a6115e61c9f557164a0 Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 09:12:00 +0200 Subject: [PATCH 45/51] add option status messages for configure/build logs --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4b7666..e0fefbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) option(ODBC "enable MathProg ODBC support" OFF) +message(STATUS "enable MathProg ODBC support: ${ODBC}") if(ODBC) find_package(ODBC) if(ODBC_FOUND) @@ -105,6 +106,7 @@ endif() include(CMakeDependentOption) cmake_dependent_option(MYSQL "enable MathProg MySQL support" OFF "BUILD_SHARED_LIBS" OFF) +message(STATUS "enable MathProg MySQL support: ${MYSQL}") if(MYSQL) find_package(MySQL) if(MYSQL_FOUND) @@ -116,6 +118,7 @@ if(MYSQL) endif() option(IS_REENTRANT "enable reentrancy support" ON) +message(STATUS "enable reentrancy support: ${IS_REENTRANT}") if(IS_REENTRANT) if ( (CMAKE_C_COMPILER_ID MATCHES "Clang") OR # matches AppleClang and Clang From 49ed2315adad1a6cdd3761199afacea1ce8ccc3f Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 09:13:23 +0200 Subject: [PATCH 46/51] added warning message when compiler not recognised for thread-local storage --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0fefbb..e2d8a95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ if(IS_REENTRANT) elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") set(TLS "__declspec(thread)") else() + message(WARNING "compiler-specific spec for thread local storage not found; if your build breaks, set 'IS_REENTRANT' option to 'OFF'") set(TLS "_Thread_local") # default to C11 standard, may break some builds if thread local storage isn't supported endif() target_compile_definitions(GLPK PUBLIC TLS=${TLS}) From 516f69f0ed56310cb58216097931b2c61d9d2f4e Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 11:13:32 +0200 Subject: [PATCH 47/51] moved example data configuration to its own function --- cmake/examples.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/examples.cmake b/cmake/examples.cmake index dc116c4..3d36334 100644 --- a/cmake/examples.cmake +++ b/cmake/examples.cmake @@ -22,7 +22,14 @@ function(add_example_folder EXAMPLE_SRC_DIRECTORY) add_c_test(${FILE_NAME}) endif() endforeach() + configure_example_data(${EXAMPLE_SRC_DIRECTORY}) +endfunction() +function(configure_example_data EXAMPLE_SRC_DIRECTORY) + #get example dir relative to source root + string(REPLACE ${CMAKE_SOURCE_DIR} "" EXAMPLE_RELATIVE_DIR ${EXAMPLE_SRC_DIRECTORY}) + #remove any leading slash + string(REGEX REPLACE "^[/|\\]+" "" EXAMPLE_RELATIVE_DIR ${EXAMPLE_RELATIVE_DIR}) # copy example data to build output folder # using `configure_file` creates a data dependence # i.e. changes in the example data will reflect in the output folder From 3b0511facc85fd637ac63d542b1bc59b68fa0e8c Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 11:15:14 +0200 Subject: [PATCH 48/51] tspsol and tsplib are now project exports, and their dependencies are no longer built as libraries --- examples/CMakeLists.txt | 3 + examples/tsp/CMakeLists.txt | 121 +++++------------------------------- 2 files changed, 18 insertions(+), 106 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c1e66d9..f1a03ee 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,6 +15,8 @@ add_executable(${PROJECT_NAMESPACE}::glpsol ALIAS glpsol) install(TARGETS glpsol EXPORT ${PROJECT_NAME}Targets) +add_subdirectory(tsp) + # GPSOL tests add_test( NAME @@ -38,6 +40,7 @@ add_example_folder(${CMAKE_CURRENT_SOURCE_DIR}) # get example subdirectories and add them SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) +list(REMOVE_ITEM SUBDIRS "tsp") # already added foreach(SUBDIR IN LISTS SUBDIRS) add_subdirectory(${SUBDIR}) endforeach() \ No newline at end of file diff --git a/examples/tsp/CMakeLists.txt b/examples/tsp/CMakeLists.txt index f122808..1c0e56b 100644 --- a/examples/tsp/CMakeLists.txt +++ b/examples/tsp/CMakeLists.txt @@ -1,127 +1,36 @@ -# I've probably done this whole thing completely wrong, but it works +include(examples) -if(APPLE) - set(CMAKE_INSTALL_RPATH - "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") -elseif(UNIX) - set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN") -endif() - -set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - -#get dir relative to source root -string(REPLACE ${CMAKE_SOURCE_DIR} "" RELATIVE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -#remove any leading slash -string(REGEX REPLACE "^[/|\\]+" "" RELATIVE_DIR ${RELATIVE_DIR}) -# multi-cfg builds -foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES) - string(TOUPPER ${OutputConfig} OUTPUTCONFIG) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${RELATIVE_DIR}) -endforeach() -# single-cfg builds -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_DIR}) - -add_library(maxflow maxflow.c) -target_include_directories( - maxflow - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) -target_compile_features(maxflow PRIVATE c_std_11) -target_link_libraries(maxflow PRIVATE - ${PROJECT_NAMESPACE}::GLPK - $<$>:m>) -add_library(${PROJECT_NAMESPACE}::maxflow ALIAS maxflow) -install(TARGETS maxflow) - -set_target_properties(maxflow PROPERTIES PREFIX "") - -add_library(mincut mincut.c) -target_include_directories( - mincut - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) -target_compile_features(mincut PRIVATE c_std_11) -target_link_libraries(mincut PRIVATE - ${PROJECT_NAMESPACE}::GLPK - ${PROJECT_NAMESPACE}::maxflow - $<$>:m>) -add_library(${PROJECT_NAMESPACE}::mincut ALIAS mincut) -install(TARGETS mincut) - -set_target_properties(mincut PROPERTIES PREFIX "") - - -add_library(misc misc.c) -target_include_directories( - misc - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) -target_compile_features(misc PRIVATE c_std_11) -target_link_libraries(misc PRIVATE - ${PROJECT_NAMESPACE}::GLPK - $<$>:m>) -add_library(${PROJECT_NAMESPACE}::misc ALIAS misc) -install(TARGETS misc) - -set_target_properties(misc PROPERTIES PREFIX "") - -add_library(tsplib tsplib.c) -target_include_directories( - tsplib - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) +add_library(tsplib tsplib.c misc.c mincut.c maxflow.c) +target_include_directories(tsplib PUBLIC $) target_compile_features(tsplib PRIVATE c_std_11) target_link_libraries(tsplib PRIVATE ${PROJECT_NAMESPACE}::GLPK - ${PROJECT_NAMESPACE}::misc +# misc $<$>:m>) add_library(${PROJECT_NAMESPACE}::tsplib ALIAS tsplib) -install(TARGETS tsplib) +install(TARGETS tsplib + EXPORT ${PROJECT_NAME}Targets) set_target_properties(tsplib PROPERTIES PREFIX "") -add_executable(tspsol main.c) -target_include_directories( - tspsol - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) +add_executable(tspsol main.c mincut.c maxflow.c) +target_include_directories(tspsol PUBLIC $) target_compile_features(tspsol PRIVATE c_std_11) target_link_libraries(tspsol PRIVATE ${PROJECT_NAMESPACE}::GLPK ${PROJECT_NAMESPACE}::tsplib - ${PROJECT_NAMESPACE}::mincut - ${PROJECT_NAMESPACE}::maxflow $<$>:m>) include(GNUInstallDirs) -install(TARGETS tspsol) +install(TARGETS tspsol + EXPORT ${PROJECT_NAME}Targets) -# copy example data to build output folder -# using `configure_file` creates a data dependence -# i.e. changes in the example data will reflect in the output folder -file(GLOB EXAMPLE_DATA_FILES "*" LIST_DIRECTORIES false) -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.[c|h]") # remove *.c and *.h files -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.am") # remove automake files -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*\\.bat") # remove batch files -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/CMakeLists\\.txt") # remove CMakeLists.txt -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile") # remove Makefiles -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/Makefile.in") # remove Makefile templates -list(FILTER EXAMPLE_DATA_FILES EXCLUDE REGEX ".*/build\\.sh") # remove build scripts -foreach(EXAMPLE_DATA_FILE IN LISTS EXAMPLE_DATA_FILES) - get_filename_component(EXAMPLE_DATA_NAME ${EXAMPLE_DATA_FILE} NAME) - if(NOT (IS_DIRECTORY ${EXAMPLE_DATA_FILE})) # `LIST_DIRECTORIES false` not reliable - configure_file( - ${EXAMPLE_DATA_FILE} - ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RELATIVE_DIR}/${EXAMPLE_DATA_NAME} - COPYONLY - ) - endif() -endforeach() +configure_example_data(${CMAKE_CURRENT_SOURCE_DIR}) if(BUILD_TESTING) + #get current dir relative to source root + string(REPLACE ${CMAKE_SOURCE_DIR} "" RELATIVE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + #remove any leading slash + string(REGEX REPLACE "^[/|\\]+" "" RELATIVE_DIR ${RELATIVE_DIR}) add_test(NAME tspsol_solve COMMAND tspsol "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RELATIVE_DIR}/sample.tsp") endif() \ No newline at end of file From dd67aef9fa62572c63dc2901730cb1d6dbce511c Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 11:23:39 +0200 Subject: [PATCH 49/51] now using ODBC::ODBC target as dependency --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d8a95..42e7cb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,8 +94,7 @@ if(ODBC) string(REGEX MATCH "/[^/\\]+$/gm" ODBC_LIB_NAME "${ODBC_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name if (GMP_LIB_NAME) target_compile_definitions(GLPK PUBLIC ODBC_DLNAME=${ODBC_LIB_NAME}) - target_link_libraries(GLPK ODBC_LIBRARIES) - target_include_directories(GLPK ODBC_INCLUDE_DIRS) + target_link_libraries(GLPK PRIVATE ODBC::ODBC) else() message(FATAL_ERROR "Could not determine ODBC/iODBC library name") endif() From b366105ede11bd210876ea58e93dfa0f24a60685 Mon Sep 17 00:00:00 2001 From: Two4 Date: Sat, 13 Nov 2021 19:38:11 +0200 Subject: [PATCH 50/51] fixed copy-paste code mistake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42e7cb7..bc42082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,7 @@ if(ODBC) message(FATAL_ERROR "Could not run 'odbc-config --cflags' or 'iodbc-config --cflags'") endif() string(REGEX MATCH "/[^/\\]+$/gm" ODBC_LIB_NAME "${ODBC_LIBRARIES}") # regexr.com/698ls strips the preceding path from the actual lib name - if (GMP_LIB_NAME) + if (ODBC_LIB_NAME) target_compile_definitions(GLPK PUBLIC ODBC_DLNAME=${ODBC_LIB_NAME}) target_link_libraries(GLPK PRIVATE ODBC::ODBC) else() From 81b239e470919345d0b01432d167781322a25d65 Mon Sep 17 00:00:00 2001 From: Two4 Date: Mon, 15 Nov 2021 10:40:25 +0200 Subject: [PATCH 51/51] removed copying of glpk lib to example directories (no longer applicable) --- src/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1dc74b1..e54948b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,11 +42,6 @@ target_link_libraries(GLPK $<$>:m>) add_library(${PROJECT_NAMESPACE}::GLPK ALIAS GLPK) -add_custom_command(TARGET GLPK POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/examples/cplex/$" - COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/examples/tsp/$" - ) - # check system libs functions and headers # define if windows environment