2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>Float parsing corner cases
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
15 <script src=
"../../js/glsl-conformance-test.js"></script>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
20 <script id=
"fshaderParsedFloatOverflowToInfinity" type=
"x-shader/x-fragment">#version
300 es
21 precision highp float;
22 out vec4 my_FragColor;
26 // Out-of-range floats should overflow to infinity
27 // GLSL ES
3.00.6 section
4.1.4 Floats:
28 //
"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"
29 float correct = isinf(
1.0e40) ?
1.0 :
0.0;
30 my_FragColor = vec4(
0.0, correct,
0.0,
1.0);
33 <script id=
"fshaderParsedFloatUnderflowToZero" type=
"x-shader/x-fragment">#version
300 es
34 precision highp float;
35 out vec4 my_FragColor;
39 // GLSL ES
3.00.6 section
4.1.4 Floats:
40 //
"A value with a magnitude too small to be represented as a mantissa and exponent is converted to zero."
41 //
1.0e-50 is small enough that it can't even be stored as subnormal.
42 float correct = (
1.0e-50 ==
0.0) ?
1.0 :
0.0;
43 my_FragColor = vec4(
0.0, correct,
0.0,
1.0);
46 <script id=
"fshaderParsedFloatSmallMantissa" type=
"x-shader/x-fragment">#version
300 es
47 precision highp float;
48 out vec4 my_FragColor;
52 // GLSL ES
3.00.6 section
4.1.4 Floats:
53 //
"There is no limit on the number of digits in any digit-sequence."
54 // The below float string has
100 zeros after the decimal point, but represents
1.0.
55 float x =
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e101;
56 my_FragColor = vec4(
0.0, x,
0.0,
1.0);
59 <script id=
"fshaderParsedFloatLargeMantissa" type=
"x-shader/x-fragment">#version
300 es
60 precision highp float;
61 out vec4 my_FragColor;
65 // GLSL ES
3.00.6 section
4.1.4 Floats:
66 //
"There is no limit on the number of digits in any digit-sequence."
67 // The below float string has
100 zeros, but represents
1.0.
68 float x =
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0e-100;
69 my_FragColor = vec4(
0.0, x,
0.0,
1.0);
72 <script id=
"fshaderParsedFloatExponentAboveMaxInt" type=
"x-shader/x-fragment">#version
300 es
73 precision highp float;
74 out vec4 my_FragColor;
78 // Out-of-range floats should overflow to infinity
79 // GLSL ES
3.00.6 section
4.1.4 Floats:
80 //
"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"
81 float correct = isinf(
1.0e2147483649) ?
1.0 :
0.0;
82 my_FragColor = vec4(
0.0, correct,
0.0,
1.0);
85 <script id=
"fshaderNonConstFloatIsInfinity" type=
"x-shader/x-fragment">#version
300 es
86 precision highp float;
87 out vec4 my_FragColor;
89 uniform float u; // Assumed to have the default value
0.0
93 // Out-of-range floats should overflow to infinity
94 // GLSL ES
3.00.6 section
4.1.4 Floats:
95 //
"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"
96 float f =
1.0e2048 - u;
97 float correct = (isinf(f) && f
> 0.0) ?
1.0 :
0.0;
98 my_FragColor = vec4(
0.0, correct,
0.0,
1.0);
101 <script id=
"fshaderNonConstFloatIsNegativeInfinity" type=
"x-shader/x-fragment">#version
300 es
102 precision highp float;
103 out vec4 my_FragColor;
105 uniform float u; // Assumed to have the default value
0.0
109 // Out-of-range floats should overflow to infinity
110 // GLSL ES
3.00.6 section
4.1.4 Floats:
111 //
"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"
112 float f = -
1.0e2048 + u;
113 float correct = (isinf(f) && f <
0.0) ?
1.0 :
0.0;
114 my_FragColor = vec4(
0.0, correct,
0.0,
1.0);
117 <script type=
"text/javascript">
121 GLSLConformanceTester
.runRenderTests([
123 fShaderId
: 'fshaderParsedFloatOverflowToInfinity',
124 fShaderSuccess
: true,
126 passMsg
: "Floats of too large magnitude should be converted infinity."
129 fShaderId
: 'fshaderParsedFloatUnderflowToZero',
130 fShaderSuccess
: true,
132 passMsg
: "Floats of too small magnitude should be converted to zero."
135 fShaderId
: 'fshaderParsedFloatSmallMantissa',
136 fShaderSuccess
: true,
138 passMsg
: "Number of digits in any digit-sequence is not limited - test with a small mantissa and large exponent."
141 fShaderId
: 'fshaderParsedFloatLargeMantissa',
142 fShaderSuccess
: true,
144 passMsg
: "Number of digits in any digit-sequence is not limited - test with a large mantissa and negative exponent."
147 fShaderId
: 'fshaderParsedFloatExponentAboveMaxInt',
148 fShaderSuccess
: true,
150 passMsg
: "Test that an exponent that slightly overflows signed 32-bit int range works."
153 fShaderId
: 'fshaderNonConstFloatIsInfinity',
154 fShaderSuccess
: true,
156 passMsg
: "Test that a non-constant float that has infinity as a value is processed correctly by isinf()."
159 fShaderId
: 'fshaderNonConstFloatIsNegativeInfinity',
160 fShaderSuccess
: true,
162 passMsg
: "Test that a non-constant float that has negative infinity as a value is processed correctly by isinf()."