Skip to content

Commit

Permalink
[css-values-4][editorial] Pull IEEE stuff into a subsection.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Aug 10, 2023
1 parent 11b6b73 commit 8927120
Showing 1 changed file with 128 additions and 87 deletions.
215 changes: 128 additions & 87 deletions css-values-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Default Highlight: css
Include Can I Use Panels: yes
</pre>
<pre class='link-defaults'>
spec: css2; type: property; text: border-collapse
spec: css2;
type: property; text: border-collapse
spec: css-color-4; type: value; text: currentcolor
spec: css-color-5; type: type; text: <color>
spec: css-color-5; type:type; text: <absolute-color-function>
Expand Down Expand Up @@ -1157,7 +1158,7 @@ URL Processing Model</h4>
[=request/client=] is |environmentSettings|,
and whose [=request/referrer=] is |environmentSettings|'s [=API base URL=].

5. Apply any <dfn>URL request modifier steps</dfn> that apply to this request.
5. Apply any <dfn export>URL request modifier steps</dfn> that apply to this request.

Note: This specification does not define any URL request modification steps,
but other specs may do so.
Expand Down Expand Up @@ -3983,7 +3984,7 @@ Numeric Constants: ''e'', ''pi''</h3>
Degenerate Numeric Constants: ''infinity'', <nobr>''-infinity''</nobr>, ''NaN''</h4>

When a [=calculation=] or a subtree of a [=calculation=]
becomes infinite or NaN,
becomes [=infinite=] or [=NaN=],
representing it with a numeric value is no longer possible.
To aid in serialization of these degenerate values,
the additional math constants
Expand Down Expand Up @@ -4197,90 +4198,6 @@ Type Checking</h3>
If it can't [=CSSNumericValue/match=] any of these,
the [=math function=] is invalid.

Division by zero is possible,
which introduces certain complications.
[=Math functions=] follow IEEE-754 semantics for these operations:

* Dividing a positive value by zero produces +∞.
* Dividing a negative value by zero produces −∞.
* Adding or subtracting ±∞ to anything produces the appropriate infinity,
unless a following rule would define it as producing NaN.
* Multiplying any value by ±∞ produces the appropriate infinity,
unless a following rule would define it as producing NaN.
* Dividing any value by ±∞ produces zero,
unless a following rule would define it as producing NaN.
* Dividing zero by zero,
dividing ±∞ by ±∞,
multiplying 0 by ±∞,
adding +∞ to −∞
(or the equivalent subtractions)
produces NaN.
* Any operation with at least one NaN argument produces NaN.

Additionally,
IEEE-754 introduces the concept of a "signed zero",
which is specifically positive or negative,
and which must be tracked within a calculation
and between nested calculations:

* Negative zero
(0⁻)
can be produced by a multiplication or division that produces zero
with exactly one negative argument
(such as ''-5 * 0'' or ''1 / (-infinity)''),
or by certain argument combinations in the other [=math functions=].

Note: Note that negative zeros don't escape a [=math function=];
as detailed below,
they're "censored" away into an "unsigned" zero.
* ''0⁻ + 0⁻''
or ''0⁻ - 0''
produces 0⁻.
All other additions or subtractions that would produce a zero
produce 0⁺.
* Multiplying or dividing 0⁻ with a positive number
(including 0⁺)
produces a negative result
(either 0⁻ or −∞),
while multiplying or dividing 0⁻ with a negative number
produces a positive result.

(In other words,
multiplying or dividing with 0⁻
follows standard sign rules.)
* When comparing 0⁺ and 0⁻,
0⁻ is less than 0⁺.
For example, ''min(0⁺, 0⁻)'' must produce 0⁻,
''max(0⁺, 0⁻)'' must produce 0⁺,
and ''clamp(0⁺, 0⁻, 1)'' must produce 0⁺.
* Unless otherwise specified,
any other operation that produces a zero
produces positive zero (0⁺).

If a <dfn export>top-level calculation</dfn>
(a [=math function=] not nested inside of another [=math function=])
would produce a value whose numeric part is NaN,
it instead act as though the numeric part is 0.
If a [=top-level calculation=]
would produce a value whose numeric part is 0⁻ or 0⁺,
it instead acts as though the numeric part is the standard "unsigned" zero.

<div class=example>
For example, ''calc(-5 * 0)'' produces an unsigned zero--
the calculation resolves to 0⁻,
but as it's a [=top-level calculation=],
it's then censored to an unsigned zero.

On the other hand, ''calc(1 / calc(-5 * 0))'' produces −∞,
same as ''calc(1 / (-5 * 0))''--
the inner calc resolves to 0⁻,
and as it's not a [=top-level calculation=],
it passes it up unchanged to the outer calc to produce −∞.
If it was censored into an unsigned zero,
it would instead produce +∞.
</div>


Note: Algebraic simplifications do not affect the validity of a [=math function=] or its resolved type.
For example, ''calc(5px - 5px + 10s)'' and ''calc(0 * 5px + 10s)'' are both invalid
due to the attempt to add a length and a time.
Expand Down Expand Up @@ -4323,6 +4240,130 @@ Type Checking</h3>
might become valid in Quirks Mode
(and have its result interpreted as a ''px'' length).

<h4 id='calc-ieee'>
Infinities, NaN, and Signed Zero</h4>

[=Math functions=] follow IEEE-754 semantics,
which means they recognize the concepts of
positive and negative zero,
positive and negative infinity,
and NaN (not a number).

However, these concepts are only retained within a [=calculation tree=];
if a <dfn export>top-level calculation</dfn>
(a [=math function=] not nested directly inside of another [=math function=])
would result in one of these special values,
they're instead "censored" into a standard representable value,
as defined below.

<dfn lt="signed zero|positive zero|negative zero" for=CSS export>Signed zeros</dfn>
(indicated here as 0⁺ or 0⁻)
can not be written directly in CSS;
''0'', ''+0'' and ''-0'' all produce the standard "unsigned" zero,
which is considered positive (0⁺)
for the purposes of these rules.

[=Signed zeroes=] are produced in the following ways:

* Negative zero
(0⁻)
can be produced by a multiplication or division that produces zero
with exactly one negative argument
(such as ''-5 * 0'' or ''1 / -infinity'').
* ''0⁻ + 0⁻''
or ''0⁻ - 0⁺''
produces 0⁻.
All other additions or subtractions that would produce a zero
produce 0⁺.
* Multiplying or dividing 0⁻ with a positive number
(including 0⁺)
produces a negative result
(either 0⁻ or −∞),
while multiplying or dividing 0⁻ with a negative number
produces a positive result.

(In other words,
multiplying or dividing with 0⁻
follows standard sign rules.)
* When comparing 0⁺ and 0⁻,
0⁻ is less than 0⁺.
For example, ''min(0⁺, 0⁻)'' must produce 0⁻,
''max(0⁺, 0⁻)'' must produce 0⁺,
and ''clamp(0⁺, 0⁻, 1)'' must produce 0⁺.
* Certain argument combinations in [=math functions=]
are defined to produce 0⁻
(for example, ''round(-1, infinity)'').
All other operations that produce a zero
produce positive zero (0⁺).

[=Signed zeroes=] do not escape a [=top-level calculation=];
they're censored into the "unsigned" zero.

<dfn lt="infinity|infinite|positive infinity|negative infinity" for=CSS export>Infinities</dfn>
(indicated here as +∞ or −∞)
can be written directly
using the [[#calc-error-constants|math constants]]
''infinity'' and ''-infinity'',
or produced as a result of some calculations:

* Dividing a value by zero produces either +∞ or −∞,
according to the standard sign rules.
* Adding or subtracting ±∞ to anything produces the appropriate infinity.
* Multiplying any value by ±∞ produces the appropriate infinity.
* Dividing any value by ±∞ produces zero.
* Certain argument combinations in [=math functions=]
are defined to produce [=infinities=]
(for example, ''pow(0, -1)'' produces +∞).

Note: The rules for producing [=NaN=], below,
supersede the above rules for producing [=infinities=].

[=Infinities=] do not escape a [=top-level calculation=];
they're clamped to the minimum or maximum value allowed in the context,
as defined in [[#calc-range]].

<dfn for=CSS export>NaN</dfn>
(short for "not a number")
is the result of certain operations
that don't have a well-defined value.
It can be written directly
using the [[#calc-error-constants|math constants]]
''NaN'',
or produced as a result of some calculations:

* Dividing zero by zero,
dividing ±∞ by ±∞,
multiplying 0 by ±∞,
adding +∞ to −∞,
or subtracting two infinities of the same sign
produces NaN.

These rules override any other result,
if there's a conflict.
For example, ''0 / 0'' is NaN, not +∞.
* Certain argument combinations in [=math functions=]
are defined to produce [=NaN=]
(for example, ''asin(2)'' produces NaN).
* Any operation with at least one NaN argument produces NaN.

[=NaN=] does not escape a [=top-level calculation=];
it's censored into a zero value

<div class=example>
For example, ''calc(-5 * 0)'' produces an unsigned zero--
the calculation resolves to 0⁻,
but as it's a [=top-level calculation=],
it's then censored to an unsigned zero.

On the other hand, ''calc(1 / calc(-5 * 0))'' produces −∞,
same as ''calc(1 / (-5 * 0))''--
the inner calc resolves to 0⁻,
and as it's not a [=top-level calculation=],
it passes it up unchanged to the outer calc to produce −∞.
If it was censored into an unsigned zero,
it would instead produce +∞.
</div>


<h3 id='calc-internal'>
Internal Representation</h3>
Expand Down

0 comments on commit 8927120

Please sign in to comment.