HTML5 最大值和值的进度范围:值太大?
HTML5 progress range of max and value: too large values?
考虑以下 MWE:
<!DOCTYPE html>
<html>
<head>
<title>Progress test</title>
</head>
<body>
<progress id="progress"></progress>
<script>
progress.max = 10000000000;
progress.value = 10000000000 / 2;
</script>
</body>
</html>
这曾经适用于 Internet Explorer、Mozilla Firefox、Google Chrome 和 Opera。但是今天我意识到它不再适用于Google Chrome;显然,值 10000000000 和 10000000000 / 2 太大了。
这让我想知道官方规范对此有何评论。他们是否保证这么大的数字应该有效(在这种情况下,Google Chrome 中存在错误),或者我的数字是否高于保证有效的最大值(在这种情况下,我很幸运它可以在 IE 和 FF 中运行)?
HTML5 specification says about the progress element:
The value and max attributes, when present, must have values that are valid floating-point numbers.
A floating-point number 定义为:
A string is a valid floating-point number if it consists of:
Optionally, a "-" (U+002D) character.
One or both of the following, in the given order:
A series of one or more ASCII digits.
A single "." (U+002E) character.
A series of one or more ASCII digits.
Optionally:
Either a "e" (U+0065) character or a "E" (U+0045) character.
Optionally, a "-" (U+002D) character or "+" (U+002B) character.
A series of one or more ASCII digits.
后来说,解析浮点数值的算法应该从IEEE 754双精度浮点数的集合中选择一个值。
根据问题:
biggest integer that can be stored in a double
IEEE 754 双精度的最大值约为 1.8 × 10^308。所以你的数字 10000000000
基本上足够小,可以用 IEEE 754 双精度表示,任何有效的 HTML5 浏览器都应该正确解释。
考虑以下 MWE:
<!DOCTYPE html>
<html>
<head>
<title>Progress test</title>
</head>
<body>
<progress id="progress"></progress>
<script>
progress.max = 10000000000;
progress.value = 10000000000 / 2;
</script>
</body>
</html>
这曾经适用于 Internet Explorer、Mozilla Firefox、Google Chrome 和 Opera。但是今天我意识到它不再适用于Google Chrome;显然,值 10000000000 和 10000000000 / 2 太大了。
这让我想知道官方规范对此有何评论。他们是否保证这么大的数字应该有效(在这种情况下,Google Chrome 中存在错误),或者我的数字是否高于保证有效的最大值(在这种情况下,我很幸运它可以在 IE 和 FF 中运行)?
HTML5 specification says about the progress element:
The value and max attributes, when present, must have values that are valid floating-point numbers.
A floating-point number 定义为:
A string is a valid floating-point number if it consists of:
Optionally, a "-" (U+002D) character. One or both of the following, in the given order: A series of one or more ASCII digits. A single "." (U+002E) character. A series of one or more ASCII digits. Optionally: Either a "e" (U+0065) character or a "E" (U+0045) character. Optionally, a "-" (U+002D) character or "+" (U+002B) character. A series of one or more ASCII digits.
后来说,解析浮点数值的算法应该从IEEE 754双精度浮点数的集合中选择一个值。
根据问题:
biggest integer that can be stored in a double
IEEE 754 双精度的最大值约为 1.8 × 10^308。所以你的数字 10000000000
基本上足够小,可以用 IEEE 754 双精度表示,任何有效的 HTML5 浏览器都应该正确解释。