GME  13
CommonMath.h
Go to the documentation of this file.
00001 
00002 #include <limits>
00003 #include <string>
00004 
00005 // return: true if str represents -Inf, Inf, or NaN
00006 static bool ParseSpecialDouble(const wchar_t* str, double& out)
00007 {
00008         const wchar_t* val = (*str == '-' && *str != '\0') ? str + 1 : str;
00009         if (_wcsnicmp(L"-Inf", str, 4) == 0 || wcsncmp(L"-1.#INF", str, 7) == 0)
00010         {
00011                 out = -std::numeric_limits<double>::infinity();
00012                 return true;
00013         }
00014         else if (_wcsnicmp(L"Inf", str, 3) == 0 || wcsncmp(L"1.#INF", str, 6) == 0)
00015         {
00016                 out = std::numeric_limits<double>::infinity();
00017                 return true;
00018         }
00019         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)
00020         {
00021                 out = std::numeric_limits<double>::quiet_NaN();
00022                 return true;
00023         }
00024         return false;
00025 }