From 177fd9c79d186cc58523a0f6ad0bd7fdd0012f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 14 Jul 2015 20:48:08 +0200 Subject: [PATCH] MathLib: make isinf and isnan more portable --- lib/mathlib.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 15c961330..b4670cc1e 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -26,6 +26,18 @@ #include +#if defined(_MSC_VER) && _MSC_VER <= 1700 // VS2012 doesn't have std::isinf and std::isnan +#define ISINF(x) (!_finite(x)) +#define ISNAN(x) (_isnan(x)) +#elif defined(__INTEL_COMPILER) +#define ISINF(x) (isinf(x)) +#define ISNAN(x) (isnan(x)) +#else // Use C++11 functions +#define ISINF(x) (std::isinf(x)) +#define ISNAN(x) (std::isnan(x)) +#endif + + MathLib::value::value(const std::string &s) : intValue(0), doubleValue(0), isUnsigned(false) { @@ -61,10 +73,11 @@ std::string MathLib::value::str() const { std::ostringstream ostr; if (type == MathLib::value::FLOAT) { - if (std::isnan(doubleValue)) + if (ISNAN(doubleValue)) return "nan.0"; - if (std::isinf(doubleValue)) + if (ISINF(doubleValue)) return (doubleValue > 0) ? "inf.0" : "-inf.0"; + ostr.precision(9); ostr << std::fixed << doubleValue;