diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index e7b5e072b..a24977f8d 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -302,6 +303,34 @@ template int IntLog2(T n) return result; } +inline bool IsInfinity(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_NINF: + case _FPCLASS_PINF: + return true; + default: + return false; + } +#else + return std::isinf(x); +#endif +} + +inline bool IsNan(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_SNAN: + case _FPCLASS_QNAN: + return true; + default: + return false; + } +#else + return std::isnan(x); +#endif +} + } // end namespace glslang #endif // _COMMON_INCLUDED_ diff --git a/glslang/MachineIndependent/Constant.cpp b/glslang/MachineIndependent/Constant.cpp index 7f5d4c4f2..5fc61dbb7 100644 --- a/glslang/MachineIndependent/Constant.cpp +++ b/glslang/MachineIndependent/Constant.cpp @@ -46,35 +46,6 @@ namespace { using namespace glslang; -typedef union { - double d; - int i[2]; -} DoubleIntUnion; - -// Some helper functions - -bool isNan(double x) -{ - DoubleIntUnion u; - // tough to find a platform independent library function, do it directly - u.d = x; - int bitPatternL = u.i[0]; - int bitPatternH = u.i[1]; - return (bitPatternH & 0x7ff80000) == 0x7ff80000 && - ((bitPatternH & 0xFFFFF) != 0 || bitPatternL != 0); -} - -bool isInf(double x) -{ - DoubleIntUnion u; - // tough to find a platform independent library function, do it directly - u.d = x; - int bitPatternL = u.i[0]; - int bitPatternH = u.i[1]; - return (bitPatternH & 0x7ff00000) == 0x7ff00000 && - (bitPatternH & 0xFFFFF) == 0 && bitPatternL == 0; -} - const double pi = 3.1415926535897932384626433832795; } // end anonymous namespace @@ -663,12 +634,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) case EOpIsNan: { - newConstArray[i].setBConst(isNan(unionArray[i].getDConst())); + newConstArray[i].setBConst(IsNan(unionArray[i].getDConst())); break; } case EOpIsInf: { - newConstArray[i].setBConst(isInf(unionArray[i].getDConst())); + newConstArray[i].setBConst(IsInfinity(unionArray[i].getDConst())); break; } diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index a0fade16c..d8a3aab5d 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -48,37 +48,6 @@ #endif #include -namespace { - -bool IsInfinity(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_NINF: - case _FPCLASS_PINF: - return true; - default: - return false; - } -#else - return std::isinf(x); -#endif -} - -bool IsNan(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_SNAN: - case _FPCLASS_QNAN: - return true; - default: - return false; - } -#else - return std::isnan(x); -#endif -} - -} namespace glslang {