[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    isnan() and isinf() checks
From:       Hasso Tepper <hasso () kde ! org>
Date:       2007-04-11 23:31:37
Message-ID: 200704120231.37547.hasso () kde ! org
[Download RAW message or body]

The C99 standard says that isinf and isnan are macros, but reality is
more complex. These might be functions in some systems (glibc has even
both!) and might require -lm. At the moment we only check whether
function exists and in the trunk we don't use -lm for check either.

Attached are patches to fix the problem for both KDE3 and KDE4. As a
side effect it also fixes detecting (_)finite in KDE4 for platforms
where it requires -lm.

Patches are tested on Linux and DragonFlyBSD. If noone objects, I will
commit tomorrow.


PS. The only thing now that makes out of box build fail on DragonFlyBSD
is the fact that we use our own copy of libtool which is just very old.
Any chance to update it? 


regards,

-- 
Hasso Tepper
KDE Estonian Team

["kjs3-isnan-isinf.patch" (text/x-diff)]

Index: kjs/configure.in.in
===================================================================
--- kjs/configure.in.in	(revision 650631)
+++ kjs/configure.in.in	(working copy)
@@ -1,19 +1,43 @@
 dnl KDE JavaScript specific configure tests
 
 AC_CHECK_HEADERS(ieeefp.h float.h)
-AC_CHECK_LIB(m, isinf, [
-  AC_DEFINE_UNQUOTED(HAVE_FUNC_ISINF, 1, [Define if you have isinf])
-])
 AC_CHECK_LIB(m, finite, [
   AC_DEFINE_UNQUOTED(HAVE_FUNC_FINITE, 1, [Define if you have finite])
 ])
 AC_CHECK_LIB(m, _finite, [
   AC_DEFINE_UNQUOTED(HAVE_FUNC__FINITE, 1, [Define if you have _finite])
 ])
-AC_CHECK_LIB(m, isnan, [
-  AC_DEFINE_UNQUOTED(HAVE_FUNC_ISNAN, 1, [Define if you have isnan])
+
+dnl The C99 standard says that isinf and isnan are macros, but they might
+dnl be functions on some platforms.
+AC_DEFUN([AC_CHECK_ISNAN],
+[
+    ac_save_libs="$LIBS"
+    LIBS="-lm"
+    AC_MSG_CHECKING([for isnan with <math.h>])
+    AC_TRY_LINK(
+	[#include <math.h>], [float f = 0.0; isnan(f)],
+	[AC_MSG_RESULT(yes)
+	    AC_DEFINE([HAVE_FUNC_ISNAN], [1], [Define if you have isnan])],
+	AC_MSG_RESULT(no)
+    )
 ])
+AC_DEFUN([AC_CHECK_ISINF],
+[
+    ac_save_libs="$LIBS"
+    LIBS="-lm"
+    AC_MSG_CHECKING([for isinf with <math.h>])
+    AC_TRY_LINK(
+	[#include <math.h>], [float f = 0.0; isinf(f)],
+	[AC_MSG_RESULT(yes)
+	    AC_DEFINE([HAVE_FUNC_ISINF], [1], [Define if you have isinf])],
+	AC_MSG_RESULT(no)
+    )
+])
 
+AC_CHECK_ISNAN
+AC_CHECK_ISINF
+
 AC_DEFUN([AC_CHECK_PCREPOSIX],
 [
   dnl define the configure option that disables pcre

["kjs4-isnan-isinf.patch" (text/x-diff)]

Index: kjs/CMakeLists.txt
===================================================================
--- kjs/CMakeLists.txt	(revision 652527)
+++ kjs/CMakeLists.txt	(working copy)
@@ -1,3 +1,4 @@
+include(CheckCSourceCompiles)
 
 project(kjs)
 KDE4_NO_ENABLE_FINAL(kjs)
@@ -10,12 +11,29 @@
 check_include_files(ieeefp.h      HAVE_IEEEFP_H)
 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
 check_include_files(valgrind/memcheck.h   HAVE_MEMCHECK_H)
+
+set (CMAKE_REQUIRED_LIBRARIES "-lm")
 check_function_exists(_finite    HAVE_FUNC__FINITE)
 check_function_exists(finite     HAVE_FUNC_FINITE)
-check_function_exists(isinf      HAVE_FUNC_ISINF)
-check_function_exists(isnan      HAVE_FUNC_ISNAN)
 
+check_c_source_compiles("
+  #include <math.h>
+  int main(){
+    float f = 0.0;
+    isnan(f);
+    return 0;
+  }
+" HAVE_FUNC_ISNAN )
 
+check_c_source_compiles("
+  #include <math.h>
+  int main(){
+    float f = 0.0;
+    isinf(f);
+    return 0;
+  }
+" HAVE_FUNC_ISINF )
+set (CMAKE_REQUIRED_LIBRARIES) # reset CMAKE_REQUIRED_LIBRARIES
 
 macro_optional_find_package(PCRE)
 macro_bool_to_01(PCRE_FOUND HAVE_PCREPOSIX)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic