Skip to content

Commit 9babfc8

Browse files
author
Awjin Ahn
authored
Merge pull request sass#2787 from Awjin/math-function-summary
More math functions, Draft 1.1
2 parents 5779211 + 26e6472 commit 9babfc8

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-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: 54 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,55 @@ 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, consider `(1px)^(1/3)`—what does
48+
the unit `px^(1/3)` mean?
49+
50+
[CSS Values and Units 4 Draft]: https://drafts.csswg.org/css-values-4/#math
51+
52+
To avoid issues like this, the exponential functions—`log()`, `pow()`, `sqrt()`
53+
accept only a unitless number as input, and output a unitless number.
54+
55+
The trig functions—`cos()`, `sin()`, `tan()`—accept a SassScript number with a
56+
unit, as long as that unit is an [angle][] type. If the input is a unitless
57+
number, it is treated as though it were in `rad`. These functions output a
58+
unitless number.
59+
60+
[angle]: https://drafts.csswg.org/css-values-4/#angles
61+
62+
The inverse trig functions—`acos()`, `asin()`, `atan()`—accept a unitless number
63+
and output a SassScript number in `rad`. `atan2()` is similar, but it accepts
64+
two unitless numbers.
65+
66+
`clamp()` accepts three SassScript numbers with [compatible][] units: the
67+
minimum value, preferred value, and maximum value. This function "clamps" the
68+
preferred value in between the minimum and maximum values, while preserving
69+
their units appropriately. For example, `clamp(1in, 15cm, 12in)` outputs `15cm`,
70+
whereas `clamp(1in, 1cm, 12in)` outputs `1in`.
71+
72+
[compatible]: ../spec/built_in_modules/math.md#compatible
73+
74+
`hypot()` accepts `n` SassScript numbers with compatible units, and outputs the
75+
length of the `n`-dimensional vector that has components equal to each of the
76+
inputs. Since the inputs' units may all be different, the output takes the unit
77+
of the first input.
78+
2879
## Variables
2980

3081
### `$e`
@@ -45,15 +96,13 @@ digits: `3.141592654`.
4596
clamp($min, $number, $max)
4697
```
4798

48-
* If the units of `$min`, `$number`, and `$max` are not [compatible][] with each
99+
* If the units of `$min`, `$number`, and `$max` are not compatible with each
49100
other, throw an error.
50101
* If `$min >= $max`, return `$min`.
51102
* If `$number <= $min`, return `$min`.
52103
* If `$number >= $max`, return `$max`.
53104
* Return `$number`.
54105

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

59108
```
@@ -145,12 +194,11 @@ sqrt($number)
145194
cos($number)
146195
```
147196

148-
* If `$number` has units but is not an [angle][], throw an error.
197+
* If `$number` has units but is not an angle, throw an error.
149198
* If `$number` is unitless, treat it as though its unit were `rad`.
150199
* If `$number == Infinity`, return `NaN` as a unitless number.
151200
* Return the [cosine][] of `$number`, as a unitless number.
152201

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

156204
#### `sin()`

0 commit comments

Comments
 (0)