@@ -2574,11 +2574,11 @@ Exponential Functions: ''pow()'', ''sqrt()'', ''hypot()''</h3>
2574
2574
''sqrt()'' is a common enough function
2575
2575
that it is provided as a convenience.)
2576
2576
2577
- The <dfn lt="hypot()">hypot(A,B )</dfn> function
2578
- contains two comma-separated [=calculations=] A and B ,
2579
- and returns the length of the hypotenuse of a right-angled triangle
2580
- with legs equal to A and B .
2581
- A and B can resolve to any <<number>> , <<dimension>> , or <<percentage>> ,
2577
+ The <dfn lt="hypot()">hypot(A, … )</dfn> function
2578
+ contains one or more comma-separated [=calculations=] ,
2579
+ and returns the length of an N-dimensional vector
2580
+ with components equal to each of the [=calculations=] .
2581
+ The argument [=calculations=] can resolve to any <<number>> , <<dimension>> , or <<percentage>> ,
2582
2582
but must have the <em> same</em> [=determine the type of a calculation|type=] ,
2583
2583
or else the function is invalid;
2584
2584
the result will have the same [=CSSNumericValue/type=] as the arguments.
@@ -2661,6 +2661,48 @@ Exponential Functions: ''pow()'', ''sqrt()'', ''hypot()''</h3>
2661
2661
Thus it's fine to let author use dimensions directly in ''hypot()'' .
2662
2662
</details>
2663
2663
2664
+ <div class=example>
2665
+ The ''pow()'' function can be useful for strategies like <a href="https://www.modularscale.com/">CSS Modular Scale</a> ,
2666
+ which relates all the font-sizes on a page to each other by a fixed ratio.
2667
+
2668
+ These sizes can be easily written into custom properties like:
2669
+
2670
+ <pre class=lang-css>
2671
+ :root {
2672
+ --h6: calc(1rem * pow(1.5, -1);
2673
+ --h5: 1rem;
2674
+ --h4: calc(1rem * pow(1.5, 2);
2675
+ --h3: calc(1rem * pow(1.5, 3);
2676
+ --h2: calc(1rem * pow(1.5, 4);
2677
+ --h1: calc(1rem * pow(1.5, 5);
2678
+ }
2679
+ </pre>
2680
+
2681
+ ...rather than writing out the values in pre-calculated numbers like ''7.6rem''
2682
+ (what ''calc(1rem * pow(1.5, 5))'' resolves to)
2683
+ which have less clear provenance when encountered in a stylesheet.
2684
+ </div>
2685
+
2686
+ <div class=example>
2687
+ With a single argument,
2688
+ ''hypot()'' gives the absolute value of its input;
2689
+ ''hypot(2em)'' and ''hypot(-2em)'' both resolve to ''2em'' .
2690
+
2691
+ With more arguments,
2692
+ it gives the size of the main diagonal of a box
2693
+ whose side lengths are given by the arguments.
2694
+ This can be useful for transform-related things,
2695
+ giving the distance that an element will actually travel
2696
+ when it's translated by a particular X, Y, and Z amount.
2697
+
2698
+ For example, ''hypot(30px, 40px)'' resolves to ''50px'' ,
2699
+ which is indeed the distance between an element's starting and ending positions
2700
+ when it's translated by a ''translate(30px, 40px)'' transform.
2701
+ If an author wanted elements to get smaller as they moved further away from their starting point
2702
+ (drawing some sort of word cloud, for example),
2703
+ they could then use this distance in their scaling factor calculations.
2704
+ </div>
2705
+
2664
2706
<h4 id="exponent-infinities">
2665
2707
Argument Ranges</h4>
2666
2708
@@ -2699,8 +2741,8 @@ Argument Ranges</h4>
2699
2741
If A is less than 0,
2700
2742
the result is NaN.
2701
2743
2702
- In ''hypot(A, B )'' ,
2703
- if either or both values are infinite,
2744
+ In ''hypot(A, … )'' ,
2745
+ if any of the inputs are infinite,
2704
2746
the result is +∞.
2705
2747
2706
2748
(See [[#calc-type-checking]] for details on how [=math functions=] handle NaN and infinities.)
0 commit comments