KhronosGroup / glslang

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

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

Closed HeXiaoZhi closed 3 months ago

HeXiaoZhi commented 1 year ago

glslang representing literal constants with double precision, so 1.0e40 and 1.0e-50 are normal values.

Shader1:

#version 300 es
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.0e40) ? 1.0 : 0.0;
    my_FragColor = vec4(0.0, correct, 0.0, 1.0);
}
#version 300 es
precision highp float;
out vec4 my_FragColor;
void main()
{
    // GLSL ES 3.00.6 section 4.1.4 Floats:
    // "A value with a magnitude too small to be represented as a mantissa and exponent is converted to zero."
    // 1.0e-50 is small enough that it can't even be stored as subnormal.
    float correct = (1.0e-50 == 0.0) ? 1.0 : 0.0;
    my_FragColor = vec4(0.0, correct, 0.0, 1.0);
}

KHR-GLES3.number_parsing.float_out_of_range_as_infinity

arcady-lunarg commented 3 months ago

I believe this has already been fixed.