diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index a8e3b38bfd..a64bd58509 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -2589,7 +2589,17 @@ TIntermConstantUnion* TIntermediate::addConstantUnion(bool b, const TSourceLoc& TIntermConstantUnion* TIntermediate::addConstantUnion(double d, TBasicType baseType, const TSourceLoc& loc, bool literal) const { assert(baseType == EbtFloat || baseType == EbtDouble || baseType == EbtFloat16); - + if (baseType == EbtFloat) + d = (float)d; + else if (baseType == EbtFloat16 && !IsInfinity(d) && !IsNan(d)) { + int exponent = (((*(unsigned long long*)&d) >> 52) & 0x7ff) - 1023; + if (exponent < -14) + d = 0.0; + else if (exponent > 15){ + (*(unsigned long long*)&d) &= ~((((unsigned long long)1) << 52) - 1); + (*(unsigned long long*)&d) |= ((unsigned long long)0x7ff) << 52; + } + } TConstUnionArray unionArray(1); unionArray[0].setDConst(d);