diff --git a/configure.in b/configure.in
index 1026c855bf2b233e3a72c69edbe8e59b87a7622b..e788419eb4f642e341fc76c7a4b1f34e2c5ea3d8 100644
--- a/configure.in
+++ b/configure.in
@@ -2006,12 +2006,20 @@ case "$target" in
     ;;
 esac
 
-# isinf() could be a function or a macro (HPUX)
-AC_MSG_CHECKING(for isinf with <math.h>)
+# Check that isinf() is available in math.h and can be used in both C and C++ 
+# code
+AC_MSG_CHECKING(for isinf in <math.h>)
 AC_TRY_LINK([#include <math.h>], [float f = 0.0; int r = isinf(f); return r],
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_ISINF, [1], [isinf() macro or function]),
- AC_MSG_RESULT(no))
+  AC_MSG_RESULT(yes)
+  AC_MSG_CHECKING(whether isinf() can be used in C++ code)
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_LINK([#include <math.h>], [float f = 0.0; int r = isinf(f); return r],
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_ISINF, [1], [isinf() macro or function]),
+    AC_MSG_RESULT(no))
+  AC_LANG_RESTORE,
+  AC_MSG_RESULT(no))
  
 CFLAGS="$ORG_CFLAGS"
 
diff --git a/include/my_global.h b/include/my_global.h
index e9b371d8d305ab97a97e9f4d61aa97caed50d665..f32a987ffb15314ffa1f5d0c66a96bfd06431360 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -792,12 +792,11 @@ typedef SOCKET_SIZE_TYPE size_socket;
 #define isnan(x) ((x) != (x))
 #endif
 
-#if !defined(HAVE_ISINF)
-/* The configure check for "isinf with math.h" has failed */
-#ifdef isinf
-#undef isinf
-#endif
-#define isinf(X) (!finite(X) && !isnan(X))
+#ifdef HAVE_ISINF
+/* isinf() can be used in both C and C++ code */
+#define my_isinf(X) isinf(X)
+#else
+#define my_isinf(X) (!finite(X) && !isnan(X))
 #endif
 
 /* Define missing math constants. */
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 14a4c4dcf4ba68527e267600516aef8cb087bf9e..adb512ec0e9a022aa4c1d55bcf3623b616bc6b08 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1980,9 +1980,9 @@ double my_double_round(double value, longlong dec, bool dec_unsigned,
   tmp=(abs_dec < array_elements(log_10) ?
        log_10[abs_dec] : pow(10.0,(double) abs_dec));
 
-  if (dec_negative && isinf(tmp))
+  if (dec_negative && my_isinf(tmp))
     tmp2= 0;
-  else if (!dec_negative && isinf(value * tmp))
+  else if (!dec_negative && my_isinf(value * tmp))
     tmp2= value;
   else if (truncate)
   {
diff --git a/strings/strtod.c b/strings/strtod.c
index 15707a9b94445ca6b3a199b720b42837974d1b40..7196cafb2c93c20393e21104cda7b8f3422e3079 100644
--- a/strings/strtod.c
+++ b/strings/strtod.c
@@ -194,7 +194,7 @@ double my_strtod(const char *str, char **end_ptr, int *error)
 done:
   *end_ptr= (char*) str;                        /* end of number */
 
-  if (overflow || isinf(result))
+  if (overflow || my_isinf(result))
   {
     result= DBL_MAX;
     *error= EOVERFLOW;