From: Amro Date: Fri, 29 Jul 2016 12:23:23 +0000 (+0300) Subject: move definition of util functions X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e1048e7227a0d747ea2fda07338580ac49c7d5ce;p=nlopt.git move definition of util functions --- diff --git a/api/general.c b/api/general.c index dc2fb38..26af0d3 100644 --- a/api/general.c +++ b/api/general.c @@ -20,54 +20,10 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include - #include "nlopt-internal.h" /*************************************************************************/ -int nlopt_isinf(double x) { - return fabs(x) >= HUGE_VAL * 0.99 -#ifdef HAVE_ISINF - || isinf(x) -#endif - ; -} - -int nlopt_isfinite(double x) { - return fabs(x) <= DBL_MAX; -} - -int nlopt_istiny(double x) -{ -#if defined(HAVE_FPCLASSIFY) - return x == 0.0 || fpclassify(x) == FP_SUBNORMAL; -#elif defined(_WIN32) - if (x == 0.0) - return 1; - else { - int c = _fpclass(x); - return c == _FPCLASS_ND || c == _FPCLASS_PD; - } -#else - return fabs(x) < 2.2250738585072014e-308; /* assume IEEE 754 double */ -#endif -} - -int nlopt_isnan(double x) -{ -#if defined(HAVE_ISNAN) - return isnan(x); -#elif defined(_WIN32) - return _isnan(x); -#else - return x != x; /* might fail with aggressive optimization */ -#endif -} - -/*************************************************************************/ - void NLOPT_STDCALL nlopt_version(int *major, int *minor, int *bugfix) { *major = MAJOR_VERSION; diff --git a/util/stop.c b/util/stop.c index 0eeed3d..3cfb8d2 100644 --- a/util/stop.c +++ b/util/stop.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -163,3 +164,46 @@ void nlopt_stop_msg(const nlopt_stopping *s, const char *format, ...) va_end(ap); } } + +/*************************************************************************/ + +int nlopt_isinf(double x) +{ + return (fabs(x) >= HUGE_VAL * 0.99) +#ifdef HAVE_ISINF + || isinf(x) +#endif + ; +} + +int nlopt_isfinite(double x) +{ + return (fabs(x) <= DBL_MAX); +} + +int nlopt_istiny(double x) +{ +#if defined(HAVE_FPCLASSIFY) + return x == 0.0 || fpclassify(x) == FP_SUBNORMAL; +#elif defined(_WIN32) + if (x == 0.0) + return 1; + else { + int c = _fpclass(x); + return c == _FPCLASS_ND || c == _FPCLASS_PD; + } +#else + return fabs(x) < 2.2250738585072014e-308; /* assume IEEE 754 double */ +#endif +} + +int nlopt_isnan(double x) +{ +#if defined(HAVE_ISNAN) + return isnan(x); +#elif defined(_WIN32) + return _isnan(x); +#else + return (x != x); /* might fail with aggressive optimization */ +#endif +}