[commit] r1903 - trunk/GME/Common

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Apr 18 13:32:30 CDT 2012


Author: ksmyth
Date: Wed Apr 18 13:32:30 2012
New Revision: 1903

Log:
Code to deserialize INF et al

Added:
   trunk/GME/Common/CommonMath.h   (contents, props changed)

Added: trunk/GME/Common/CommonMath.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/GME/Common/CommonMath.h	Wed Apr 18 13:32:30 2012	(r1903)
@@ -0,0 +1,25 @@
+
+#include <limits>
+#include <string>
+
+// return: true if str represents -Inf, Inf, or NaN
+static bool ParseSpecialDouble(const wchar_t* str, double& out)
+{
+	const wchar_t* val = (*str == '-' && *str != '\0') ? str + 1 : str;
+	if (_wcsnicmp(L"-Inf", str, 4) == 0 || wcsncmp(L"-1.#INF", str, 7) == 0)
+	{
+		out = -std::numeric_limits<double>::infinity();
+		return true;
+	}
+	else if (_wcsnicmp(L"Inf", str, 3) == 0 || wcsncmp(L"1.#INF", str, 6) == 0)
+	{
+		out = std::numeric_limits<double>::infinity();
+		return true;
+	}
+	else if (_wcsnicmp(L"NaN", val, 3) == 0 || wcsncmp(L"1.#IND", val, 7) == 0 || wcsncmp(L"1.#QNAN", val, 7) == 0 || wcsncmp(L"1.#SNAN", val, 7) == 0)
+	{
+		out = std::numeric_limits<double>::quiet_NaN();
+		return true;
+	}
+	return false;
+}


More information about the gme-commit mailing list