Skip to content

Commit c65b579

Browse files
committed
More math functions, Draft 1.1
Add background and summary sections
1 parent 5779211 commit c65b579

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Draft 1.1
2+
3+
* Added Background and Summary sections.
4+
5+
## Draft 1
6+
7+
* Initial draft.

proposal/more-math-functions.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# More Math Functions: Draft 1
1+
# More Math Functions: Draft 1.1
22

33
*[(Issue)](https://github.com/sass/sass/issues/851)*
44

55
This proposal adds the following members to the built-in `sass:math` module.
66

77
## Table of Contents
8+
* [Background](#background)
9+
* [Summary](#summary)
810
* [Variables](#variables)
911
* [`$e`](#e)
1012
* [`$pi`](#pi)
@@ -25,6 +27,54 @@ This proposal adds the following members to the built-in `sass:math` module.
2527
* [`atan2()`](#atan2)
2628
* [Edge cases](#edge-cases)
2729

30+
## Background
31+
32+
> This section is non-normative.
33+
34+
Sass recently implemented a module system with a new built-in `sass:math`
35+
module. The demand for built-in math functions can now be fulfilled safely by
36+
implementing them inside this module. None of these new functions will be made
37+
available on the global namespace.
38+
39+
## Summary
40+
41+
> This section is non-normative.
42+
43+
This proposal defines Sassified versions of all the mathematical functions in
44+
the [CSS Values and Units 4 Draft][], as well as logarithms and the constants
45+
`e` and `pi`. Each function is basically equivalent to its mathematical form,
46+
with stricter unit handling. Proper unit handling prevents these functions from
47+
creating meaningless units. For instance, what is the unit of `(1px)`<sup><code>2</code></sup>? A `px`<sup><code>2</code></sup>?
48+
49+
[CSS Values and Units 4 Draft]: https://drafts.csswg.org/css-values-4/#math
50+
51+
To avoid issues like this, the exponential functions—`log()`, `pow()`, `sqrt()`
52+
accept only a unitless number as input, and output a unitless number.
53+
54+
The trig functions—`cos()`, `sin()`, `tan()`—accept a SassScript number with a
55+
unit, as long as that unit is an [angle][] type. If the input is a unitless
56+
number, it is treated as though it were in `rad`. These functions output a
57+
unitless number.
58+
59+
[angle]: https://drafts.csswg.org/css-values-4/#angles
60+
61+
The inverse trig functions—`acos()`, `asin()`, `atan()`—accept a unitless number
62+
and output a SassScript number in `rad`. `atan2()` is similar, but it accepts
63+
two unitless numbers.
64+
65+
`clamp()` accepts three SassScript numbers with [compatible][] units: the
66+
minimum value, preferred value, and maximum value. This function "clamps" the
67+
preferred value in between the minimum and maximum values, while preserving
68+
their units appropriately. For example, `clamp(1in, 15cm, 12in)` outputs `15cm`,
69+
whereas `clamp(1in, 1cm, 12in)` outputs `1in`.
70+
71+
[compatible]: ../spec/built_in_modules/math.md#compatible
72+
73+
`hypot()` accepts `n` SassScript numbers with compatible units, and outputs the
74+
length of the `n`-dimensional vector that has components equal to each of the
75+
inputs. Since the inputs' units may all be different, the output takes the unit
76+
of the first input.
77+
2878
## Variables
2979

3080
### `$e`
@@ -45,15 +95,13 @@ digits: `3.141592654`.
4595
clamp($min, $number, $max)
4696
```
4797

48-
* If the units of `$min`, `$number`, and `$max` are not [compatible][] with each
98+
* If the units of `$min`, `$number`, and `$max` are not compatible with each
4999
other, throw an error.
50100
* If `$min >= $max`, return `$min`.
51101
* If `$number <= $min`, return `$min`.
52102
* If `$number >= $max`, return `$max`.
53103
* Return `$number`.
54104

55-
[compatible]: ../spec/built_in_modules/math.md#compatible
56-
57105
### `hypot()`
58106

59107
```
@@ -145,12 +193,11 @@ sqrt($number)
145193
cos($number)
146194
```
147195

148-
* If `$number` has units but is not an [angle][], throw an error.
196+
* If `$number` has units but is not an angle, throw an error.
149197
* If `$number` is unitless, treat it as though its unit were `rad`.
150198
* If `$number == Infinity`, return `NaN` as a unitless number.
151199
* Return the [cosine][] of `$number`, as a unitless number.
152200

153-
[angle]: https://drafts.csswg.org/css-values-4/#angles
154201
[cosine]: https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions
155202

156203
#### `sin()`

0 commit comments

Comments
 (0)