Constellation / iv

ECMAScript Lexer / Parser / Interpreter / VM / method JIT written in C++
BSD 2-Clause "Simplified" License
417 stars 33 forks source link

Use _isnan() in iv/date_utils.h for MSVC compatibility #94

Closed rednaxelafx closed 11 years ago

rednaxelafx commented 11 years ago

MSVC (upto VS2012) doesn't implement std::isnan() in <cmath>, but it does provide _isnan() since VC6.

A quick-n-dirty patch to make date_utils.h compile in VS2012 is:

diff --git a/iv/date_utils.h b/iv/date_utils.h
index f987fd2..e728de3 100644
--- a/iv/date_utils.h
+++ b/iv/date_utils.h
@@ -379,8 +379,14 @@ class DateInstance {
   }

   void SetValue(double value) {
+#ifdef _MSC_VER
+#define ISNAN(n) _isnan(n)
+#else
+#define ISNAN(n) std::isnan(n)
+#endif
     value_ = value;
-    invalidate_ = (std::isnan(value)) ? NG : INVALIDATED;
+    invalidate_ = (ISNAN(value)) ? NG : INVALIDATED;
+#undef ISNAN
   }

   bool IsValid() const { return invalidate_ != NG; }

It could be written in a more elegant way, though. I'll leave that to Suzuki-san :-)

Constellation commented 11 years ago

We can use iv::core::math::IsNaN in iv/platform_math.h

Constellation commented 11 years ago

Fixed in f6c99f12193c3cd656b37ac90a94c7d816f375d7. Thanks!

rednaxelafx commented 11 years ago

Thank you!