KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.9k stars 815 forks source link

Out-of-range floats should overflow to infinity #3555

Closed jimihem closed 3 months ago

jimihem commented 3 months ago

"2147483649" of 1.0e2147483649 is out of range that positive 32bits int can store.

precision highp float;
out vec4 my_FragColor;
void main()
{
    // Out-of-range floats should overflow to infinity
    // GLSL ES 3.00.6 section 4.1.4 Floats:
    // "If the value of the floating point number is too large (small) to be stored as a single precision value, it is converted to positive (negative) infinity"
    float correct = isinf(1.0e2147483649) ? 1.0 : 0.0;
    my_FragColor = vec4(0.0, correct, 0.0, 1.0);
}
jimihem commented 3 months ago

PR 3388 has fixed some cases about float overflow. This PR fix a new case. The max positive interger that 32bit int can represent is 2147483647, in this case it's 2147483649.

arcady-lunarg commented 3 months ago

Won't your "fix" still break if the exponent is larger than can be represented in 64 bits? It's also not necessary, any exponent with an absolute value above 310 is too big to fit in a double anyway. So IMO it would make more sense to just check the exponent and clamp it to some arbitrary "too big" value which will be handled correctly by the rest of the code.

arcady-lunarg commented 3 months ago

I'm going to do my own version of this PR, #3562 but I'll keep the part of the commit that adds the test (with you as the author), thanks for the test.