1
- # More Math Functions: Draft 1.1
1
+ # More Math Functions: Draft 2
2
2
3
3
* [ (Issue)] ( https://github.com/sass/sass/issues/851 ) *
4
4
@@ -7,6 +7,8 @@ This proposal adds the following members to the built-in `sass:math` module.
7
7
## Table of Contents
8
8
* [ Background] ( #background )
9
9
* [ Summary] ( #summary )
10
+ * [ Semantics] ( #semantics )
11
+ * [ Built-in Module Variables] ( #built-in-module-variables )
10
12
* [ Variables] ( #variables )
11
13
* [ ` $e ` ] ( #e )
12
14
* [ ` $pi ` ] ( #pi )
@@ -60,7 +62,7 @@ unitless number.
60
62
[ angle ] : https://drafts.csswg.org/css-values-4/#angles
61
63
62
64
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
65
+ and output a SassScript number in ` deg ` . ` atan2() ` is similar, but it accepts
64
66
two unitless numbers.
65
67
66
68
` clamp() ` accepts three SassScript numbers with [ compatible] [ ] units: the
@@ -76,17 +78,73 @@ length of the `n`-dimensional vector that has components equal to each of the
76
78
inputs. Since the inputs' units may all be different, the output takes the unit
77
79
of the first input.
78
80
81
+ ## Semantics
82
+
83
+ ### Built-in Module Variables
84
+
85
+ Variables defined in built-in modules are not modifiable. As such, this proposal
86
+ modifies the semantics of [ Executing a Variable Declaration] [ ] within the
87
+ [ Variables spec] [ ] to read as follows:
88
+
89
+ [ Executing a Variable Declaration ] : ../spec/variables.md#executing-a-variable-declaration
90
+ [ Variables spec ] : ../spec/variables.md
91
+
92
+ To execute a ` VariableDeclaration ` ` declaration ` :
93
+
94
+ * Let ` value ` be the result of evaluating ` declaration ` 's ` Expression ` .
95
+
96
+ * Let ` name ` be ` declaration ` 's ` Variable ` .
97
+
98
+ * ** Let ` resolved ` be the result of [ resolving a variable] [ ] named ` name ` .**
99
+
100
+ [ resolving a variable ] : ../spec/modules.md#resolving-a-member
101
+
102
+ * If ` name ` is a ` NamespacedVariable ` and ` declaration ` has a ` !global ` flag,
103
+ throw an error.
104
+
105
+ * ** Otherwise, if ` resolved ` is a variable from a built-in module, throw an
106
+ error.**
107
+
108
+ * Otherwise, if ` declaration ` is outside of any block of statements, * or*
109
+ ` declaration ` has a ` !global ` flag, * or* ` name ` is a ` NamespacedVariable ` :
110
+
111
+ * ~~ Let ` resolved ` be the result of [ resolving a variable] [ ] named ` name ` using
112
+ ` file ` , ` uses ` , and ` import ` .~~
113
+
114
+ (...)
115
+
116
+ * Otherwise, if ` declaration ` is within one or more blocks associated with
117
+ ` @if ` , ` @each ` , ` @for ` , and/or ` @while ` rules * and no other blocks* :
118
+
119
+ * ~~ Let ` resolved ` be the result of [ resolving a variable] [ ] named ` name ` .~~
120
+
121
+ (...)
122
+
123
+ * ~~ Otherwise, if no block containing ` declaration ` has a [ scope] [ ] with a
124
+ variable named ` name ` , set the innermost block's scope's variable ` name ` to
125
+ ` value ` .~~
126
+
127
+ [ scope ] : ../spec/variables.md#scope
128
+
129
+ * ** Otherwise, if ` resolved ` is null, get the innermost block containing
130
+ ` declaration ` and set its scope's variable ` name ` to ` value ` .**
131
+
132
+ * ~~ Otherwise, let ` scope ` be the scope of the innermost block such that ` scope `
133
+ already has a variable named ` name ` .~~
134
+
135
+ * ** Otherwise, set ` resolved ` 's value to ` value ` .**
136
+
79
137
## Variables
80
138
81
139
### ` $e `
82
140
83
141
Equal to the value of the mathematical constant ` e ` with a precision of 10
84
- digits: ` 2.718281828 ` .
142
+ digits after the decimal point : ` 2.7182818285 ` .
85
143
86
144
### ` $pi `
87
145
88
146
Equal to the value of the mathematical constant ` pi ` with a precision of 10
89
- digits: ` 3.141592654 ` .
147
+ digits after the decimal point : ` 3.1415926536 ` .
90
148
91
149
## Functions
92
150
@@ -98,6 +156,7 @@ clamp($min, $number, $max)
98
156
99
157
* If the units of ` $min ` , ` $number ` , and ` $max ` are not compatible with each
100
158
other, throw an error.
159
+ * If some arguments have units and some do not, throw an error.
101
160
* If ` $min >= $max ` , return ` $min ` .
102
161
* If ` $number <= $min ` , return ` $min ` .
103
162
* If ` $number >= $max ` , return ` $max ` .
@@ -113,7 +172,7 @@ hypot($arguments...)
113
172
* If some arguments have units and some do not, throw an error.
114
173
* If all arguments are unitless, the return value is unitless.
115
174
* Otherwise, the return value takes the unit of the leftmost argument.
116
- * If any argument is ` Infinity ` , return ` Infinity ` .
175
+ * If any argument equals ` Infinity ` or ` - Infinity` , return ` Infinity ` .
117
176
* Return the square root of the sum of the squares of each argument.
118
177
119
178
### Exponentiation
@@ -124,12 +183,12 @@ hypot($arguments...)
124
183
log($number, $base: null)
125
184
```
126
185
127
- * If ` $number ` has units or ` $number < 0 ` , throw an error.
186
+ * If ` $number ` has units, throw an error.
128
187
* If ` $base ` is null:
188
+ * If ` $number < 0 ` , return ` NaN ` as a unitless number.
129
189
* If ` $number == 0 ` , return ` -Infinity ` as a unitless number.
130
190
* If ` $number == Infinity ` , return ` Infinity ` as a unitless number.
131
191
* Return the [ natural log] [ ] of ` $number ` , as a unitless number.
132
- * Otherwise, if ` $base < 0 ` or ` $base == 0 ` or ` $base == 1 ` , throw an error.
133
192
* Otherwise, return the natural log of ` $number ` divided by the natural log of
134
193
` $base ` , as a unitless number.
135
194
@@ -145,7 +204,7 @@ pow($base, $exponent)
145
204
146
205
* If ` $exponent == 0 ` , return ` 1 ` as a unitless number.
147
206
148
- * Otherwise, if ` $exponent == Infinity ` :
207
+ * Otherwise, if ` $exponent == Infinity ` or ` $exponent == -Infinity ` :
149
208
* If ` $base == 1 ` or ` $base == -1 ` , return ` NaN ` as a unitless number.
150
209
* If ` $base < -1 ` or ` $base > 1 ` and if ` $exponent > 0 ` , * or* if ` $base > -1 `
151
210
and ` $base < 1 ` and ` $exponent < 0 ` , return ` Infinity ` as a
@@ -196,7 +255,8 @@ cos($number)
196
255
197
256
* If ` $number ` has units but is not an angle, throw an error.
198
257
* If ` $number ` is unitless, treat it as though its unit were ` rad ` .
199
- * If ` $number == Infinity ` , return ` NaN ` as a unitless number.
258
+ * If ` $number == Infinity ` or ` $number == -Infinity ` , return ` NaN ` as a unitless
259
+ number.
200
260
* Return the [ cosine] [ ] of ` $number ` , as a unitless number.
201
261
202
262
[ cosine ] : https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions
@@ -209,7 +269,8 @@ sin($number)
209
269
210
270
* If ` $number ` has units but is not an angle, throw an error.
211
271
* If ` $number ` is unitless, treat it as though its unit were ` rad ` .
212
- * If ` $number == Infinity ` , return ` NaN ` as a unitless number.
272
+ * If ` $number == Infinity ` or ` $number == -Infinity ` , return ` NaN ` as a unitless
273
+ number.
213
274
* If ` $number == -0 ` , return ` -0 ` as a unitless number.
214
275
* Return the [ sine] [ ] of ` $number ` , as a unitless number.
215
276
@@ -223,7 +284,8 @@ tan($number)
223
284
224
285
* If ` $number ` has units but is not an angle, throw an error.
225
286
* If ` $number ` is unitless, treat it as though its unit were ` rad ` .
226
- * If ` $number == Infinity ` , return ` NaN ` as a unitless number.
287
+ * If ` $number == Infinity ` or ` $number == -Infinity ` , return ` NaN ` as a unitless
288
+ number.
227
289
* If ` $number == -0 ` , return ` -0 ` as a unitless number.
228
290
* If ` $number ` is equivalent to ` 90deg +/- 360deg * n ` , where ` n ` is any
229
291
integer, return ` Infinity ` as a unitless number.
@@ -240,9 +302,9 @@ acos($number)
240
302
```
241
303
242
304
* If ` $number ` has units, throw an error.
243
- * If ` $number < -1 ` or ` $number > 1 ` , return ` NaN ` as a number in ` rad ` .
244
- * If ` $number == 1 ` , return ` 0rad ` .
245
- * Return the [ arccosine] [ ] of ` $number ` , as a number in ` rad ` .
305
+ * If ` $number < -1 ` or ` $number > 1 ` , return ` NaN ` as a number in ` deg ` .
306
+ * If ` $number == 1 ` , return ` 0deg ` .
307
+ * Return the [ arccosine] [ ] of ` $number ` , as a number in ` deg ` .
246
308
247
309
[ arccosine ] : https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties
248
310
@@ -253,9 +315,9 @@ asin($number)
253
315
```
254
316
255
317
* If ` $number ` has units, throw an error.
256
- * If ` $number < -1 ` or ` $number > 1 ` , return ` NaN ` as a number in ` rad ` .
257
- * If ` $number == -0 ` , return ` -0rad ` .
258
- * Return the [ arcsine] [ ] of ` $number ` , as a number in ` rad ` .
318
+ * If ` $number < -1 ` or ` $number > 1 ` , return ` NaN ` as a number in ` deg ` .
319
+ * If ` $number == -0 ` , return ` -0deg ` .
320
+ * Return the [ arcsine] [ ] of ` $number ` , as a number in ` deg ` .
259
321
260
322
[ arcsine ] : https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties
261
323
@@ -266,29 +328,28 @@ atan($number)
266
328
```
267
329
268
330
* If ` $number ` has units, throw an error.
269
- * If ` $number == -0 ` , return ` -0rad ` .
270
- * If ` $number == -Infinity ` , return ` -0.5rad * pi ` .
271
- * If ` $number == Infinity ` , return ` 0.5rad * pi ` .
272
- * Return the [ arctangent] [ ] of ` $number ` , as a number in ` rad ` .
331
+ * If ` $number == -0 ` , return ` -0deg ` .
332
+ * If ` $number == -Infinity ` , return ` -90deg ` .
333
+ * If ` $number == Infinity ` , return ` 90deg ` .
334
+ * Return the [ arctangent] [ ] of ` $number ` , as a number in ` deg ` .
273
335
274
336
[ arctangent ] : https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties
275
337
276
338
#### ` atan2() `
277
339
278
340
> ` atan2($y, $x) ` is distinct from ` atan($y / $x) ` because it preserves the
279
341
> quadrant of the point in question. For example, ` atan2(1, -1) ` corresponds to
280
- > the point ` (-1, 1) ` and returns ` 0.75rad * pi ` . In contrast, ` atan(1 / -1) `
281
- > and ` atan(-1 / 1) ` resolve first to ` atan(-1) ` , so both return
282
- > ` -0.25rad * pi ` .
342
+ > the point ` (-1, 1) ` and returns ` 135deg ` . In contrast, ` atan(1 / -1) ` and
343
+ > ` atan(-1 / 1) ` resolve first to ` atan(-1) ` , so both return ` -45deg ` .
283
344
284
345
```
285
346
atan2($y, $x)
286
347
```
287
348
288
349
* If ` $y ` and ` $x ` are not compatible, throw an error.
289
350
* If the inputs match one of the following edge cases, return the provided
290
- number in ` rad ` . Otherwise, return the [ 2-argument arctangent] [ ] of ` $y ` and
291
- ` $x ` , as a number in ` rad ` .
351
+ number. Otherwise, return the [ 2-argument arctangent] [ ] of ` $y ` and ` $x ` , as a
352
+ number in ` deg ` .
292
353
293
354
[ 2-argument arctangent ] : https://en.wikipedia.org/wiki/Atan2
294
355
@@ -314,57 +375,57 @@ atan2($y, $x)
314
375
<tr>
315
376
<th rowspan="6">Y</th>
316
377
<th>−Infinity</th>
317
- <td>-0.75 * pi </td>
318
- <td>-0.5 * pi </td>
319
- <td>-0.5 * pi </td>
320
- <td>-0.5 * pi </td>
321
- <td>-0.5 * pi </td>
322
- <td>-0.25 * pi </td>
378
+ <td>-135deg </td>
379
+ <td>-90deg </td>
380
+ <td>-90deg </td>
381
+ <td>-90deg </td>
382
+ <td>-90deg </td>
383
+ <td>-45deg </td>
323
384
</tr>
324
385
<tr>
325
386
<th>-finite</th>
326
- <td>-pi </td>
387
+ <td>-180deg </td>
327
388
<td></td>
328
- <td>-0.5 * pi </td>
329
- <td>-0.5 * pi </td>
389
+ <td>-90deg </td>
390
+ <td>-90deg </td>
330
391
<td></td>
331
- <td>-0 </td>
392
+ <td>-0deg </td>
332
393
</tr>
333
394
<tr>
334
395
<th>-0</th>
335
- <td>-pi </td>
336
- <td>-pi </td>
337
- <td>-pi </td>
338
- <td>-0 </td>
339
- <td>-0 </td>
340
- <td>-0 </td>
396
+ <td>-180deg </td>
397
+ <td>-180deg </td>
398
+ <td>-180deg </td>
399
+ <td>-0deg </td>
400
+ <td>-0deg </td>
401
+ <td>-0deg </td>
341
402
</tr>
342
403
<tr>
343
404
<th>0</th>
344
- <td>pi </td>
345
- <td>pi </td>
346
- <td>pi </td>
347
- <td>0 </td>
348
- <td>0 </td>
349
- <td>0 </td>
405
+ <td>180deg </td>
406
+ <td>180deg </td>
407
+ <td>180deg </td>
408
+ <td>0deg </td>
409
+ <td>0deg </td>
410
+ <td>0deg </td>
350
411
</tr>
351
412
<tr>
352
413
<th>finite</th>
353
- <td>pi </td>
414
+ <td>180deg </td>
354
415
<td></td>
355
- <td>0.5 * pi </td>
356
- <td>0.5 * pi </td>
416
+ <td>90deg </td>
417
+ <td>90deg </td>
357
418
<td></td>
358
- <td>0 </td>
419
+ <td>0deg </td>
359
420
</tr>
360
421
<tr>
361
422
<th>Infinity</th>
362
- <td>0.75 * pi </td>
363
- <td>0.5 * pi </td>
364
- <td>0.5 * pi </td>
365
- <td>0.5 * pi </td>
366
- <td>0.5 * pi </td>
367
- <td>0.25 * pi </td>
423
+ <td>135deg </td>
424
+ <td>90deg </td>
425
+ <td>90deg </td>
426
+ <td>90deg </td>
427
+ <td>90deg </td>
428
+ <td>45deg </td>
368
429
</tr>
369
430
</tbody >
370
431
</table >
0 commit comments