From f2393c38b13637c661c6484b7f5aab559406ceaf Mon Sep 17 00:00:00 2001 From: stevenj Date: Thu, 29 Jul 2010 22:35:46 -0400 Subject: [PATCH] handle missing C99/IEEE copysign function, e.g. for WWin32; thanks to Benoit Scherrer for the bug report darcs-hash:20100730023546-c8de0-2d82e58615ba8036734a2b104aefb4a53a88f9b5.gz --- configure.ac | 8 ++++++++ util/nlopt-util.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index 7c88f3d..b5c6d2a 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,14 @@ if test "$ok" = "yes"; then fi AC_MSG_RESULT(${ok}) +AC_MSG_CHECKING([for copysign]) +AC_TRY_LINK([#include +], [double x = copysign(3.14159, -2.7183);], ok=yes, ok=no) +if test "$ok" = "yes"; then + AC_DEFINE(HAVE_COPYSIGN,1,[Define if the copysign function/macro is available.]) +fi +AC_MSG_RESULT(${ok}) + dnl ----------------------------------------------------------------------- if test "x$with_cxx" = xyes; then diff --git a/util/nlopt-util.h b/util/nlopt-util.h index 9b4f51f..222ce6f 100644 --- a/util/nlopt-util.h +++ b/util/nlopt-util.h @@ -35,6 +35,11 @@ # define HUGE_VAL REPLACEMENT_HUGE_VAL #endif +#ifndef HAVE_COPYSIGN + /* not quite right for y == -0, but good enough for us */ +# define copysign(x, y) ((y) < 0 ? -fabs(x) : fabs(x)) +#endif + #ifdef __cplusplus extern "C" { -- 2.30.2