Skip to content

Commit 1f8f9e8

Browse files
committed
[css-values-4] Rephrase some trig and type bits to be more precise, and allow referring to types of calculations more easily.
1 parent 0338143 commit 1f8f9e8

File tree

1 file changed

+70
-63
lines changed

1 file changed

+70
-63
lines changed

css-values-4/Overview.bs

+70-63
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,8 @@ Basic Arithmetic: ''calc()''</h3>
22852285

22862286
A ''calc()'' function contains a single <dfn export for="calc()">calculation</dfn>,
22872287
which is a sequence of values interspersed with operators,
2288-
and possibly grouped by parentheses,
2288+
and possibly grouped by parentheses
2289+
(matching the <<calc-sum>> grammar),
22892290
which represents the result of evaluating the expression
22902291
using standard operator precedence rules.
22912292
(<css>*</css> and <css>/</css> bind tighter than <css>+</css> and <css>-</css>,
@@ -2494,7 +2495,7 @@ Type Checking</h3>
24942495

24952496
A [=math function=] can be many possible types,
24962497
such as <<length>>, <<number>>, etc.,
2497-
depending on the expression it contains,
2498+
depending on the [=calculations=] it contains,
24982499
as defined below.
24992500
It can be used anywhere a value of that type is allowed.
25002501

@@ -2519,70 +2520,76 @@ Type Checking</h3>
25192520
and to make division-by-zero detectable at parse time.
25202521
This version now relaxes those restrictions.
25212522

2522-
[=Math functions=] allow arbitrary expressions,
2523-
so long as the expression as a whole resolves to a singular unit
2524-
according to the following rules:
2525-
2526-
* At a <css>+</css> or <css>-</css> sub-expression,
2527-
attempt to [=add two types|add the types=] of the left and right arguments.
2528-
If this returns failure,
2529-
the entire [=math function=] is invalid.
2530-
Otherwise, the sub-expression's [=CSSNumericValue/type=] is the returned type.
2531-
2532-
* At a <css>*</css> sub-expression,
2533-
[=multiply two types|multiply the types=] of the left and right arguments.
2534-
The sub-expression's [=CSSNumericValue/type=] is the returned result.
2535-
2536-
* At a <css>/</css> sub-expression,
2537-
let |left type| be the result of finding the [=CSSNumericValue/types=] of its left argument,
2538-
and |right type| be the result of finding the [=CSSNumericValue/types=] of its right argument
2539-
and then [=invert a type|inverting=] it.
2540-
2541-
The sub-expression's [=CSSNumericValue/type=] is the result of
2542-
[=multiply two types|multiplying=] the |left type| and |right type|.
2543-
2544-
* Anything else is a terminal value,
2545-
whose [=CSSNumericValue/type=] is determined based on its CSS type:
2546-
2547-
<dl class=switch>
2548-
: <<number>>
2549-
: <<integer>>
2550-
:: the [=CSSNumericValue/type=] is «[ ]» (empty map)
2551-
: <<length>>
2552-
:: the [=CSSNumericValue/type=] is «[ "length" → 1 ]»
2553-
: <<angle>>
2554-
:: the [=CSSNumericValue/type=] is «[ "angle" → 1 ]»
2555-
: <<time>>
2556-
:: the [=CSSNumericValue/type=] is «[ "time" → 1 ]»
2557-
: <<frequency>>
2558-
:: the [=CSSNumericValue/type=] is «[ "frequency" → 1 ]»
2559-
: <<resolution>>
2560-
:: the [=CSSNumericValue/type=] is «[ "resolution" → 1 ]»
2561-
: <<flex>>
2562-
:: the [=CSSNumericValue/type=] is «[ "flex" → 1 ]»
2563-
: <<percentage>>
2564-
::
2565-
If, in the context in which the [=math function=] is placed,
2566-
<<percentage>>s are resolved relative to another type of value
2567-
(such as in 'width', where <<percentage>> is resolved against a <<length>>),
2568-
and that other type is <em>not</em> <<number>>,
2569-
the [=CSSNumericValue/type=] is determined as the other type.
2570-
2571-
Otherwise,
2572-
the [=CSSNumericValue/type=] is «[ "percent" → 1 ]».
2573-
: anything else
2574-
:: The [=math function=] is invalid.
2575-
</dl>
2576-
2577-
In all cases, the associated [=percent hint=] is null.
2523+
<div algorithm>
2524+
To <dfn>determine the type of a [=calculation=]</dfn>:
2525+
2526+
* At a <css>+</css> or <css>-</css> sub-expression,
2527+
attempt to [=add two types|add the types=] of the left and right arguments.
2528+
If this returns failure,
2529+
the entire [=calculation’s=] type is failure.
2530+
Otherwise, the sub-expression's [=CSSNumericValue/type=] is the returned type.
2531+
2532+
* At a <css>*</css> sub-expression,
2533+
[=multiply two types|multiply the types=] of the left and right arguments.
2534+
The sub-expression's [=CSSNumericValue/type=] is the returned result.
2535+
2536+
* At a <css>/</css> sub-expression,
2537+
let |left type| be the result of finding the [=CSSNumericValue/types=] of its left argument,
2538+
and |right type| be the result of finding the [=CSSNumericValue/types=] of its right argument
2539+
and then [=invert a type|inverting=] it.
2540+
2541+
The sub-expression's [=CSSNumericValue/type=] is the result of
2542+
[=multiply two types|multiplying=] the |left type| and |right type|.
2543+
2544+
* Anything else is a terminal value,
2545+
whose [=CSSNumericValue/type=] is determined based on its CSS type:
2546+
2547+
<dl class=switch>
2548+
: <<number>>
2549+
: <<integer>>
2550+
:: the [=CSSNumericValue/type=] is «[ ]» (empty map)
2551+
: <<length>>
2552+
:: the [=CSSNumericValue/type=] is «[ "length" → 1 ]»
2553+
: <<angle>>
2554+
:: the [=CSSNumericValue/type=] is «[ "angle" → 1 ]»
2555+
: <<time>>
2556+
:: the [=CSSNumericValue/type=] is «[ "time" → 1 ]»
2557+
: <<frequency>>
2558+
:: the [=CSSNumericValue/type=] is «[ "frequency" → 1 ]»
2559+
: <<resolution>>
2560+
:: the [=CSSNumericValue/type=] is «[ "resolution" → 1 ]»
2561+
: <<flex>>
2562+
:: the [=CSSNumericValue/type=] is «[ "flex" → 1 ]»
2563+
: <<percentage>>
2564+
::
2565+
If, in the context in which the [=math function=]
2566+
containing this [=calculation=] is placed,
2567+
<<percentage>>s are resolved relative to another type of value
2568+
(such as in 'width', where <<percentage>> is resolved against a <<length>>),
2569+
and that other type is <em>not</em> <<number>>,
2570+
the [=CSSNumericValue/type=] is determined as the other type.
2571+
2572+
Otherwise,
2573+
the [=CSSNumericValue/type=] is «[ "percent" → 1 ]».
2574+
: anything else
2575+
:: The [=calculation’s=] type is failure.
2576+
</dl>
2577+
2578+
In all cases, the associated [=percent hint=] is null.
2579+
</div>
2580+
2581+
[=Math functions=] themselves have [=CSSNumericValue/types=],
2582+
according to their contained [=calculations=]:
25782583

25792584
* The [=CSSNumericValue/type=] of a ''calc()'' expression
2580-
is the [=CSSNumericValue/type=] of its contained expression.
2581-
The [=CSSNumericValue/type=] of a ''min()'', ''max()'', or ''clamp()'' expression
2585+
is the [=CSSNumericValue/type=] of its contained [=calculation=].
2586+
* The [=CSSNumericValue/type=] of a ''min()'', ''max()'', or ''clamp()'' expression
25822587
is the result of [=add two types|adding the types=]
2583-
of its comma-separated expressions.
2584-
If the result is failure,
2585-
the entire [=math function=] is invalid.
2588+
of its comma-separated [=calculations=].
2589+
2590+
For each of the above,
2591+
if the [=CSSNumericValue/type=] is failure,
2592+
the [=math function=] is invalid.
25862593

25872594
A [=math function=] resolves to <<number>>, <<length>>, <<angle>>, <<time>>, <<frequency>>, <<resolution>>, <<flex>>, or <<percentage>>
25882595
according to which of those productions its [=CSSNumericValue/type=] [=CSSNumericValue/matches=].

0 commit comments

Comments
 (0)