diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx
index 39642d76e..f05a58917 100644
--- a/src/AIModel/AIAircraft.cxx
+++ b/src/AIModel/AIAircraft.cxx
@@ -33,16 +33,11 @@
 #include <simgear/structure/exception.hxx>
 
 #include <string>
-#include <math.h>
-#include <time.h>
-
-#ifdef _MSC_VER
-#  include <float.h>
-#  define isfinite(x) _finite(x)
-#else
-#  define isfinite(x) std::isfinite(x)
-#endif
+#include <cmath>
+#include <ctime>
 
+// defined in AIShip.cxx
+extern double fgIsFinite(double x);
 
 #include "AIAircraft.hxx"
 #include "performancedata.hxx"
@@ -945,7 +940,7 @@ void FGAIAircraft::controlHeading(FGAIWaypoint* curr) {
         SG_NORMALIZE_RANGE(calc_bearing, 0.0, 360.0);
     }
 
-    if (isfinite(calc_bearing)) {
+    if (fgIsFinite(calc_bearing)) {
         double hdg_error = calc_bearing - tgt_heading;
         if (fabs(hdg_error) > 0.01) {
             TurnTo( calc_bearing );
diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx
index 5d94dd284..d82c3963d 100644
--- a/src/AIModel/AIShip.cxx
+++ b/src/AIModel/AIShip.cxx
@@ -21,15 +21,15 @@
 #  include <config.h>
 #endif
 
+#include <cmath>
+
 #ifdef _MSC_VER
 #  include <float.h>
-#  define isfinite(x) _finite(x)
+    double fgIsFinite(double x) { return _finite(x); }
 #else
-#  define isfinite(x) std::isfinite(x)
+    double fgIsFinite(double x) { return std::isfinite(x); }
 #endif
 
-#include <math.h>
-
 #include <simgear/sg_inlines.h>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/timing/sg_time.hxx>
@@ -792,7 +792,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
     //   now revise the required course for the next way point
     _course = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->getLatitude(), curr->getLongitude());
 
-    if (isfinite(_course))
+    if (fgIsFinite(_course))
         TurnTo(_course);
     else
         SG_LOG(SG_AI, SG_ALERT, "AIShip: Bearing or Range is not a finite number");