diff --git a/src/config.h.in b/src/config.h.in
index fd45c73..723251a 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -463,3 +463,9 @@
 
 /* Define if GTK+ GUI is to be linked against GTK+ 3 */
 #undef USE_GTK3
+
+/* Define if we have isinf() */
+#undef HAVE_ISINF
+
+/* Define if we have isnan() */
+#undef HAVE_ISNAN
diff --git a/src/configure.in b/src/configure.in
index acbccde..c508ad7 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -3159,6 +3159,7 @@ AC_HEADER_TIME
 AC_CHECK_TYPE(ino_t, long)
 AC_CHECK_TYPE(dev_t, unsigned)
 AC_C_BIGENDIAN(,,,)
+AC_C_INLINE
 
 AC_MSG_CHECKING(for rlim_t)
 if eval "test \"`echo '$''{'ac_cv_type_rlim_t'+set}'`\" = set"; then
@@ -3577,7 +3578,7 @@ AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \
 	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
 	sigvec strcasecmp strerror strftime stricmp strncasecmp \
 	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
-	usleep utime utimes)
+	usleep utime utimes isinf isnan)
 AC_FUNC_FSEEKO
 
 dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when
diff --git a/src/json.c b/src/json.c
index a42faec..f58bcda 100644
--- a/src/json.c
+++ b/src/json.c
@@ -23,10 +23,35 @@
    /* for isnan() and isinf() */
 #  include <math.h>
 # endif
-# if defined(WIN32) && !defined(isnan)
-#  define isnan(x) _isnan(x)
-#  define isinf(x) (!_finite(x) && !_isnan(x))
-# endif
+# ifndef HAVE_ISNAN
+#  if defined(WIN32)
+#   define isnan(x) _isnan(x)
+#  else
+#   define isnan(x) \
+    (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
+     : sizeof (x) == sizeof (double) ? isnan_d (x) \
+     : isnan_f (x))
+    static __inline__ int isnan_f  (float       x) { return x != x; }
+    static __inline__ int isnan_d  (double      x) { return x != x; }
+    static __inline__ int isnan_ld (long double x) { return x != x; }
+#  endif
+# endif /* !defined(HAVE_ISNAN) */
+# ifndef HAVE_ISINF
+#  if defined(WIN32)
+#   define isinf(x) (!_finite(x) && !_isnan(x))
+#  else
+#    define isinf(x) \
+    (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
+     : sizeof (x) == sizeof (double) ? isinf_d (x) \
+     : isinf_f (x))
+    static __inline__ int isinf_f  (float       x)
+    { return !isnan (x) && isnan (x - x); }
+    static __inline__ int isinf_d  (double      x)
+    { return !isnan (x) && isnan (x - x); }
+    static __inline__ int isinf_ld (long double x)
+    { return !isnan (x) && isnan (x - x); }
+#  endif
+# endif /* !defined(HAVE_ISINF) */
 # if !defined(INFINITY) && defined(DBL_MAX)
 #  define INFINITY (DBL_MAX+DBL_MAX)
 # endif
