From b2b275f55434bfaf2958ae4b4afc8024b90c066d Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Tue, 12 Mar 2024 22:00:33 +0100 Subject: [PATCH] added CMAKE-check for existence of _j0 or j0, should fix issue https://github.com/jkriege2/JKQtPlotter/issues/124 --- .../jkqtplotter_common_compilersettings.cmake | 9 ++ cmake/jkqtplotter_macros.cmake | 13 ++ lib/jkqtcommon/jkqtpmathtools.h | 124 ++++++++++-------- lib/jkqtmath/jkqtpmathparser.cpp | 73 ++++++----- 4 files changed, 128 insertions(+), 91 deletions(-) diff --git a/cmake/jkqtplotter_common_compilersettings.cmake b/cmake/jkqtplotter_common_compilersettings.cmake index bd427aa4ac2..6fa222ebafc 100644 --- a/cmake/jkqtplotter_common_compilersettings.cmake +++ b/cmake/jkqtplotter_common_compilersettings.cmake @@ -10,3 +10,12 @@ math(EXPR JKQtPlotter_BIT_DEPTH ${CMAKE_SIZEOF_VOID_P}*8) find_package( CImg QUIET ) find_package( OpenCV QUIET ) + +include(CheckFunctionExists) + +set(CMAKE_REQUIRED_INCLUDES "cmath") +CHECK_FUNCTION_EXISTS(j0 JKQtPlotter_HAS_j0) +CHECK_FUNCTION_EXISTS(_j0 JKQtPlotter_HAS__j0) +CHECK_FUNCTION_EXISTS(y0 JKQtPlotter_HAS_y0) +CHECK_FUNCTION_EXISTS(_y0 JKQtPlotter_HAS__y0) +CHECK_FUNCTION_EXISTS(__y0 JKQtPlotter_HAS___y0) diff --git a/cmake/jkqtplotter_macros.cmake b/cmake/jkqtplotter_macros.cmake index 0d5ae0e9bac..15b2e320779 100644 --- a/cmake/jkqtplotter_macros.cmake +++ b/cmake/jkqtplotter_macros.cmake @@ -38,6 +38,19 @@ function(jkqtplotter_setDefaultLibOptions TARGETNAME libBaseName PRECOMPHEADERFI target_compile_definitions(${TARGETNAME} PUBLIC NOMINMAX) endif() + if(JKQtPlotter_HAS_j0) + target_compile_definitions(${TARGETNAME} PUBLIC JKQtPlotter_HAS_j0) + endif() + if(JKQtPlotter_HAS__j0) + target_compile_definitions(${TARGETNAME} PUBLIC JKQtPlotter_HAS__j0) + endif() + if(JKQtPlotter_HAS_y0) + target_compile_definitions(${TARGETNAME} PUBLIC JKQtPlotter_HAS_y0) + endif() + if(JKQtPlotter_HAS__y0) + target_compile_definitions(${TARGETNAME} PUBLIC JKQtPlotter_HAS__y0) + endif() + # enable TIMING INFO output (if activated by option JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT) if(JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT) target_compile_definitions(${TARGETNAME} PRIVATE JKQTBP_AUTOTIMER) diff --git a/lib/jkqtcommon/jkqtpmathtools.h b/lib/jkqtcommon/jkqtpmathtools.h index 1086c6543d0..c9ba6fb01af 100644 --- a/lib/jkqtcommon/jkqtpmathtools.h +++ b/lib/jkqtcommon/jkqtpmathtools.h @@ -391,77 +391,85 @@ inline T jkqtp_inversePropSaveDefault(const T& v) { return jkqtp_inversePropSave(v, std::numeric_limits::epsilon()*100.0); } -/*! \brief j0() function (without compiler issues) - \ingroup jkqtptools_math_basic +#if defined(JKQtPlotter_HAS_j0) || defined(JKQtPlotter_HAS__j0) -*/ -inline double jkqtp_j0(double x) { -#if Q_CC_MSVC - return _j0(x); -#else - return j0(x); -#endif -} + /*! \brief j0() function (without compiler issues) + \ingroup jkqtptools_math_basic -/*! \brief j1() function (without compiler issues) - \ingroup jkqtptools_math_basic + */ + inline double jkqtp_j0(double x) { + #ifdef JKQtPlotter_HAS__j0 + return _j0(x); + #elif defined(JKQtPlotter_HAS_j0) + return j0(x); + #endif + } -*/ -inline double jkqtp_j1(double x) { -#if Q_CC_MSVC - return _j1(x); -#else - return j1(x); -#endif -} + /*! \brief j1() function (without compiler issues) + \ingroup jkqtptools_math_basic -/*! \brief y0() function (without compiler issues) - \ingroup jkqtptools_math_basic + */ + inline double jkqtp_j1(double x) { + #ifdef JKQtPlotter_HAS__j0 + return _j1(x); + #elif defined(JKQtPlotter_HAS_j0) + return j1(x); + #endif + } -*/ -inline double jkqtp_y0(double x) { -#if Q_CC_MSVC - return _y0(x); -#else - return y0(x); + /*! \brief jn() function (without compiler issues) + \ingroup jkqtptools_math_basic + + */ + inline double jkqtp_jn(int n, double x) { + #ifdef JKQtPlotter_HAS__j0 + return _jn(n,x); + #elif defined(JKQtPlotter_HAS_j0) + return jn(n,x); + #endif + } #endif -} -/*! \brief y1() function (without compiler issues) - \ingroup jkqtptools_math_basic -*/ -inline double jkqtp_y1(double x) { -#if Q_CC_MSVC - return _y1(x); -#else - return y1(x); -#endif -} +#if defined(JKQtPlotter_HAS_y0) || defined(JKQtPlotter_HAS__y0) + /*! \brief y0() function (without compiler issues) + \ingroup jkqtptools_math_basic -/*! \brief jn() function (without compiler issues) - \ingroup jkqtptools_math_basic + */ + inline double jkqtp_y0(double x) { + #ifdef JKQtPlotter_HAS__y0 + return _y0(x); + #elif defined(JKQtPlotter_HAS_y0) + return y0(x); + #endif + } -*/ -inline double jkqtp_jn(int n, double x) { -#if Q_CC_MSVC - return _jn(n,x); -#else - return jn(n,x); -#endif -} + /*! \brief y1() function (without compiler issues) + \ingroup jkqtptools_math_basic -/*! \brief yn() function (without compiler issues) - \ingroup jkqtptools_math_basic + */ + inline double jkqtp_y1(double x) { + #ifdef JKQtPlotter_HAS__y0 + return _y1(x); + #elif defined(JKQtPlotter_HAS_y0) + return y1(x); + #endif + } -*/ -inline double jkqtp_yn(int n, double x) { -#if Q_CC_MSVC - return _yn(n,x); -#else - return yn(n,x); + + /*! \brief yn() function (without compiler issues) + \ingroup jkqtptools_math_basic + + */ + inline double jkqtp_yn(int n, double x) { + #ifdef JKQtPlotter_HAS__y0 + return _yn(n,x); + #elif defined(JKQtPlotter_HAS_y0) + return yn(n,x); + #endif + } #endif -} + /** \brief calculate the distance between two QPointF points * \ingroup jkqtptools_math_basic diff --git a/lib/jkqtmath/jkqtpmathparser.cpp b/lib/jkqtmath/jkqtpmathparser.cpp index 0b6e1abfc43..bd77c46c21b 100644 --- a/lib/jkqtmath/jkqtpmathparser.cpp +++ b/lib/jkqtmath/jkqtpmathparser.cpp @@ -324,16 +324,13 @@ namespace { // anonymous namespace to limit availability to this module (CPP-fil return r; } +#if defined(JKQtPlotter_HAS_j0) || defined(JKQtPlotter_HAS__j0) JKQTPMathParser::jkmpResult fJ0(JKQTPMathParser::jkmpResult* params, unsigned char n, JKQTPMathParser* p){ JKQTPMathParser::jkmpResult r; r.type=JKQTPMathParser::jkmpDouble; if (n!=1) p->jkmpError("j0 accepts 1 argument"); if (params[0].type!=JKQTPMathParser::jkmpDouble) p->jkmpError("j0 needs double argument"); -#if Q_CC_MSVC - r.num = _j0(params[0].num); -#else - r.num = j0(params[0].num); -#endif + r.num = jkqtp_j0(params[0].num); return r; } @@ -342,23 +339,41 @@ namespace { // anonymous namespace to limit availability to this module (CPP-fil r.type=JKQTPMathParser::jkmpDouble; if (n!=1) p->jkmpError("j1 accepts 1 argument"); if (params[0].type!=JKQTPMathParser::jkmpDouble) p->jkmpError("j1 needs double argument"); -#if Q_CC_MSVC - r.num=_j1(params[0].num); -#else - r.num=j1(params[0].num); +#ifdef JKQtPlotter_HAS_j0 + r.num = j1(params[0].num); +#elif defined(JKQtPlotter_HAS__j0) + r.num = _j1(params[0].num); #endif return r; } + JKQTPMathParser::jkmpResult fJn(JKQTPMathParser::jkmpResult* params, unsigned char n, JKQTPMathParser* p){ + JKQTPMathParser::jkmpResult r; + r.type=JKQTPMathParser::jkmpDouble; + if (n!=2) p->jkmpError("jn accepts 2 argument"); + if ((params[0].type!=JKQTPMathParser::jkmpDouble)||(params[1].type!=JKQTPMathParser::jkmpDouble)) p->jkmpError("jn needs double argument"); +#ifdef JKQtPlotter_HAS_j0 + r.num=_jn(static_cast(params[0].num), params[1].num); +#elif defined(JKQtPlotter_HAS__j0) + r.num=jn(static_cast(params[0].num), params[1].num); +#endif + return r; + } + +#endif + + + +#if defined(JKQtPlotter_HAS_y0) || defined(JKQtPlotter_HAS__y0) JKQTPMathParser::jkmpResult fY0(JKQTPMathParser::jkmpResult* params, unsigned char n, JKQTPMathParser* p){ JKQTPMathParser::jkmpResult r; r.type=JKQTPMathParser::jkmpDouble; if (n!=1) p->jkmpError("y0 accepts 1 argument"); if (params[0].type!=JKQTPMathParser::jkmpDouble) p->jkmpError("y0 needs double argument"); -#if Q_CC_MSVC - r.num=_y0(params[0].num); -#else - r.num=y0(params[0].num); +#ifdef JKQtPlotter_HAS_y0 + r.num = y0(params[0].num); +#elif defined(JKQtPlotter_HAS__y0) + r.num = _y0(params[0].num); #endif return r; } @@ -368,10 +383,10 @@ namespace { // anonymous namespace to limit availability to this module (CPP-fil r.type=JKQTPMathParser::jkmpDouble; if (n!=1) p->jkmpError("y1 accepts 1 argument"); if (params[0].type!=JKQTPMathParser::jkmpDouble) p->jkmpError("y1 needs double argument"); -#if Q_CC_MSVC - r.num=_y1(params[0].num); -#else - r.num=y1(params[0].num); +#ifdef JKQtPlotter_HAS_y0 + r.num = y1(params[0].num); +#elif defined(JKQtPlotter_HAS__y0) + r.num = _y1(params[0].num); #endif return r; } @@ -381,26 +396,14 @@ namespace { // anonymous namespace to limit availability to this module (CPP-fil r.type=JKQTPMathParser::jkmpDouble; if (n!=2) p->jkmpError("yn accepts 2 argument"); if ((params[0].type!=JKQTPMathParser::jkmpDouble)||(params[1].type!=JKQTPMathParser::jkmpDouble)) p->jkmpError("yn needs double argument"); -#if Q_CC_MSVC - r.num=_yn(static_cast(params[0].num), params[1].num); -#else - r.num=yn(static_cast(params[0].num), params[1].num); +#ifdef JKQtPlotter_HAS_y0 + r.num=_yn(static_cast(params[0].num), params[1].num); +#elif defined(JKQtPlotter_HAS__y0) + r.num=yn(static_cast(params[0].num), params[1].num); #endif return r; } - - JKQTPMathParser::jkmpResult fJn(JKQTPMathParser::jkmpResult* params, unsigned char n, JKQTPMathParser* p){ - JKQTPMathParser::jkmpResult r; - r.type=JKQTPMathParser::jkmpDouble; - if (n!=2) p->jkmpError("jn accepts 2 argument"); - if ((params[0].type!=JKQTPMathParser::jkmpDouble)||(params[1].type!=JKQTPMathParser::jkmpDouble)) p->jkmpError("jn needs double argument"); -#if Q_CC_MSVC - r.num=_jn(static_cast(params[0].num), params[1].num); -#else - r.num=jn(static_cast(params[0].num), params[1].num); #endif - return r; - } JKQTPMathParser::jkmpResult fSRand(JKQTPMathParser::jkmpResult* params, unsigned char n, JKQTPMathParser* p){ JKQTPMathParser::jkmpResult r; @@ -700,12 +703,16 @@ void JKQTPMathParser::addStandardFunctions(){ addFunction("erfc", fErfc); addFunction("lgamma", flGamma); addFunction("tgamma", ftGamma); +#if defined(JKQtPlotter_HAS_j0) || defined(JKQtPlotter_HAS__j0) addFunction("j0", fJ0); addFunction("j1", fJ1); addFunction("jn", fJn); +#endif +#if defined(JKQtPlotter_HAS_y0) || defined(JKQtPlotter_HAS__y0) addFunction("y0", fY0); addFunction("y1", fY1); addFunction("yn", fYn); +#endif addFunction("rand", fRand); addFunction("srand", fSRand); addFunction("ceil", fCeil);