From: <and...@us...> - 2009-02-24 08:51:07
|
Revision: 9599 http://plplot.svn.sourceforge.net/plplot/?rev=9599&view=rev Author: andrewross Date: 2009-02-24 08:51:03 +0000 (Tue, 24 Feb 2009) Log Message: ----------- More tweaks to isnan, isinf, finite checks and macros to make them more portable. Modified Paths: -------------- trunk/cmake/modules/plplot.cmake trunk/include/plplot.h trunk/src/pdfutils.c Modified: trunk/cmake/modules/plplot.cmake =================================================================== --- trunk/cmake/modules/plplot.cmake 2009-02-24 05:15:26 UTC (rev 9598) +++ trunk/cmake/modules/plplot.cmake 2009-02-24 08:51:03 UTC (rev 9599) @@ -25,6 +25,7 @@ # Need these modules to do subsequent checks. include(CheckIncludeFiles) include(CheckFunctionExists) +include(CheckSymbolExists) include(CheckPrototypeExists) macro(TRANSFORM_VERSION _numerical_result _version) @@ -185,17 +186,25 @@ include(CheckFunctionExists) check_function_exists(popen HAVE_POPEN) check_function_exists(usleep PL_HAVE_USLEEP) -check_function_exists(isinf HAVE_ISINF) -check_function_exists(finite HAVE_FINITE) + +# Check for FP functions, including underscored version which +# are sometimes all that is available on windows +check_symbol_exists(finite "math.h" HAVE_FINITE) if(NOT HAVE_FINITE) - check_function_exists(_finite _HAVE_FINITE) + check_symbolnction_exists(_finite "math.h" _HAVE_FINITE) set(HAVE_FINITE ${_HAVE_FINITE} CACHE INTERNAL "Have function _finite") endif(NOT HAVE_FINITE) -check_function_exists(isnan HAVE_ISNAN) +check_symbol_exists(isnan "math.h" HAVE_ISNAN) if(NOT HAVE_ISNAN) - check_function_exists(_isnan _HAVE_ISNAN) + check_symbol_exists(_isnan "math.h" _HAVE_ISNAN) set(HAVE_ISNAN ${_HAVE_ISNAN} CACHE INTERNAL "Have function _isnan") endif(NOT HAVE_ISNAN) +check_symbol_exists(isinf "math.h" HAVE_ISINF) +if(NOT HAVE_ISINF) + check_symbol_exists(_isinf "math.h" _HAVE_ISINF) + set(HAVE_ISINF ${_HAVE_ISINF} CACHE INTERNAL "Have function _isinf") +endif(NOT HAVE_ISINF) + check_function_exists(snprintf PL_HAVE_SNPRINTF) if(NOT PL_HAVE_SNPRINTF) check_function_exists(_snprintf _PL_HAVE_SNPRINTF) Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-02-24 05:15:26 UTC (rev 9598) +++ trunk/include/plplot.h 2009-02-24 08:51:03 UTC (rev 9599) @@ -187,18 +187,28 @@ * Add in missing isnan / isinf functions on some platforms \*--------------------------------------------------------------------------*/ -#if defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__)) +#if defined(_HAVE_ISNAN) # define isnan _isnan +#endif +#if defined(_HAVE_ISINF) # define isinf _isinf -#else -# if !defined(HAVE_ISNAN) -# define isnan(x) ((x) != (x)) -# endif -# if !defined(HAVE_ISINF) -# define isinf(x) (!isnan(x) && isnan(x-x)) -# endif #endif +#if defined(_HAVE_FINITE) +# define finite _finite +#endif +/* Note these replacements follow the old BSD convention and not + * C99. In particular isinf does not distinguish +/- inf. +#if !defined(HAVE_ISNAN) +# define isnan(x) ((x) != (x)) +#endif +#if !defined(HAVE_ISINF) +# define isinf(x) (!isnan(x) && isnan(x-x)) +#endif +#if !defined(HAVE_FINITE) +# define finite(x) (!isnan(x-x)) +#endif + /* Check if C99 HUGE_VAL macro is available - if not then * define a replacement */ #ifndef HUGE_VAL Modified: trunk/src/pdfutils.c =================================================================== --- trunk/src/pdfutils.c 2009-02-24 05:15:26 UTC (rev 9598) +++ trunk/src/pdfutils.c 2009-02-24 08:51:03 UTC (rev 9599) @@ -917,7 +917,7 @@ int i, j; PLFLT m, M; - if (isnan(f[0][0]) || isinf(f[0][0])) { + if (!finite(f[0][0])) { M = -HUGE_VAL; m = HUGE_VAL; } @@ -926,7 +926,7 @@ for (i = 0; i < nx; i++) { for (j = 0; j < ny; j++) { - if (isnan(f[i][j]) || isinf(f[i][j])) continue; + if (!finite(f[i][j])) continue; if (f[i][j] > M) M = f[i][j]; if (f[i][j] < m) m = f[i][j]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |