diff --git a/configure b/configure
index 14d00e6eecc6cf55bae4bd8d2b568088e6f59749..6439605a63ae5e66d99f89f61bfbda4ca880ee84 100755
--- a/configure
+++ b/configure
@@ -2442,6 +2442,7 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
 fi
 { echo "$as_me:$LINENO: using CFLAGS=$CFLAGS" >&5
 echo "$as_me: using CFLAGS=$CFLAGS" >&6;}
+
 # Check if the compiler still works with the template settings
 echo "$as_me:$LINENO: checking whether the C compiler still works" >&5
 echo $ECHO_N "checking whether the C compiler still works... $ECHO_C" >&6
@@ -2488,6 +2489,52 @@ echo "$as_me: error: cannot proceed" >&2;}
    { (exit 1); exit 1; }; }
 fi
 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+
+# Defend against gcc -ffastmath
+if test "$GCC" = yes; then
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+#ifdef __FAST_MATH__
+choke me
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+{ { echo "$as_me:$LINENO: error: do not put -ffast-math in CFLAGS" >&5
+echo "$as_me: error: do not put -ffast-math in CFLAGS" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
diff --git a/configure.in b/configure.in
index 15f2b727548878e1813176b3bb637ab344dd165b..4241a711a4a97429a19aed5a9b7230be23b7c240 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.209 2002/09/17 04:27:41 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.210 2002/09/20 18:38:57 petere Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -253,12 +253,21 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
   CFLAGS="$CFLAGS -g"
 fi
 AC_MSG_NOTICE([using CFLAGS=$CFLAGS])
+
 # Check if the compiler still works with the template settings
 AC_MSG_CHECKING([whether the C compiler still works])
 AC_TRY_LINK([], [return 0;],
   [AC_MSG_RESULT(yes)],
   [AC_MSG_RESULT(no)
    AC_MSG_ERROR([cannot proceed])])
+
+# Defend against gcc -ffastmath
+if test "$GCC" = yes; then
+AC_TRY_COMPILE([], [@%:@ifdef __FAST_MATH__
+choke me
+@%:@endif], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
+fi
+
 AC_PROG_CPP
 AC_SUBST(GCC)