Re: [csswg-drafts] [css-values-4] The rest of the JS math functions (#4688)

The CSS Working Group just discussed `the rest of the JS Math functions`, and agreed to the following:

* `RESOLVED: add these 5 -  abs, log, exp, and the two constants e and pi`

<details><summary>The full IRC log of that discussion</summary>
&lt;bkardell_> topic: the rest of the JS Math functions<br>
&lt;bkardell_> TabAtkins: I went through all of the Math functions and reviewed for consistency...<br>
&lt;astearns> github: https://github.com/w3c/csswg-drafts/issues/4688<br>
&lt;bkardell_> TabAtkins: in the issue I listed out the functions and constants - I just dumped the object in chrome, I assume everyone has the same thing...<br>
&lt;bkardell_> TabAtkins: I seprated them into categories<br>
&lt;bkardell_> TabAtkins: a handfull of algebra stuff - abs, cube root<br>
&lt;bkardell_> TabAtkins: you can do these yourself if you know how, but it's fine with me to just go ahead and match for parity/consistency<br>
&lt;bkardell_> TabAtkins: low value, but reasonable<br>
&lt;bkardell_> heycam: if we have this goal of 'if it is on the math object and there is no reason to not include it here'... it seems even more odd to me that round would devitate from this<br>
&lt;bkardell_> TabAtkins: exact correspondance is not my goal, we already can't match exactly because we have to include precision<br>
&lt;bkardell_> fantasai: If we aren't going for exact correspondance, we should maybe not add cube root<br>
&lt;dbaron> +1 for adding 'abs' and not adding 'cbrt'<br>
&lt;florian> +!<br>
&lt;bkardell_> fantasai: I do think we should add abs() because people are unlikely to understand there is anothe way to do that, it's not as intuitive<br>
&lt;fantasai> s/cube root/cube root right now; if there's demand for it later, we can add it later/<br>
&lt;RossenTheReal> q?<br>
&lt;bkardell_> dbaron: I think there is a small chance that it applies here, one reason some of the weird functions exist in JS might be because they can be made faster than the non-weird version<br>
&lt;bkardell_> TabAtkins: is that an argument for doing it or not ?<br>
&lt;bkardell_> dbaron: it might be an argument for someone to look into it<br>
&lt;bkardell_> fantasai: you could optimize it anyway<br>
&lt;bkardell_> dbaron: it would be harder<br>
&lt;bkardell_> (oriol demonstrates math the scribe couldn't understand)<br>
&lt;dbaron> Oriol was pointing out that cbrt(-8) is -2 whereas pow(-8, 1/3) is NaN<br>
&lt;dbaron> And, particularly, fractions 1/N where N is odd are not representable exactly unless N is 1 or -1.<br>
&lt;bkardell_> TabAtkins:  next up - hyperbolic trig functions... I don't know use cases here in CSS?<br>
&lt;bkardell_> TabAtkins: can skip this entire category unless someone needs to object?<br>
&lt;bkardell_> fremy: if you have the exponent function you should be good<br>
&lt;bkardell_> TabAtkins: next - the family of e related functions -- log(), log 2, log 10<br>
&lt;bkardell_> in JavaScript it was like this - I suggest we just pass in instead of 2, 10<br>
&lt;dbaron> TabAtkins: log() is 2 argument with base defaulting to e<br>
&lt;bkardell_> TabAtkins: suggesting we just add log() and possibly exp()?<br>
&lt;bkardell_> fantasai: I think I agree with your basic take, I think we just do log() now and exp later<br>
&lt;bkardell_> TabAtkins: next is rounding, we already discussed<br>
&lt;dbaron> Ah, Mercator projection drawing math uses asinh().<br>
&lt;bkardell_> TabAtkins: the last thing is constants...<br>
&lt;bkardell_> TabAtkins:  I can see you wanting to use some of these - Pi, E ..<br>
&lt;bkardell_> TabAtkins:  should we add these as single argument functions?  it seems like there's a challenge with globally reserved keywords<br>
&lt;dbaron> TabAtkins: Would break animation-names of e and pi<br>
&lt;bkardell_> heycam: can you not make it global, just in calc?<br>
&lt;chris> maybe make them ε and π (the greek letters) to avoid conflicts<br>
&lt;bkardell_> TabAtkins: ... maybe, probably<br>
&lt;fantasai> +1 to heycam's suggestion<br>
&lt;bkardell_> RossenTheReal: do we need them for now?<br>
&lt;bkardell_> TabAtkins: no non-ascii things please<br>
&lt;bkardell_> florian: keeping the parser non-breaking seems useful<br>
&lt;bkardell_> fantasai:  we have an intent to use them anywhere -- as long as it is not a great complication to the parser it seems like a win<br>
&lt;dbaron> could we add them in a function like const(pi)?<br>
&lt;florian> env(pi)<br>
&lt;fantasai> s/use them anywhere/add keywords to calc() someday anyway/<br>
&lt;bkardell_> TabAtkins: actually, the units thing is not a terrible idea<br>
&lt;fantasai> s/a win/a usability win/<br>
&lt;bkardell_> dbaron: one thing that is painful about e is its interaction with exponential notation<br>
&lt;heycam> Tab there is responding to my /me joke to make pi and e be units<br>
&lt;bkardell_> dbaron: we already support things like 1e<br>
&lt;cbiesinger> s/1e/1e1/<br>
&lt;bkardell_> dbaron:  I saw a suggestion - what if we stuck these inside of some other function?<br>
&lt;bkardell_> TabAtkins: we want this to be short is the counter argument I guess, but const is not bad<br>
&lt;dbaron> 1e1e is pretty ugly (in terms of having pi and e be units)<br>
&lt;bkardell_> myles: it could be math.e to match javascript<br>
&lt;bkardell_> fantasai: that would change the parser<br>
&lt;bkardell_> TabAtkins: which of these 3 options do we like?<br>
&lt;TabAtkins> 1. "e" and "pi" allowed in calc() as keywords<br>
&lt;TabAtkins> 2. e() and pi() available everywhere<br>
&lt;leaverou> const(e) might be more clear than e for people reading others' code<br>
&lt;TabAtkins> 3. const(e) and const(pi) available everywhere<br>
&lt;fremy> 2<br>
&lt;fantasai> 1<br>
&lt;florian> 1<br>
&lt;leaverou> 3<br>
&lt;fantasai> Note that 1 allows calc(e) everywhere<br>
&lt;dbaron> could also be math(pi) rather than const(pi)<br>
&lt;faceless2_> 2<br>
&lt;astearns> 1 or 3<br>
&lt;iank_> not 3<br>
&lt;chris> 3<br>
&lt;fantasai> dbaron, let's take that as a variant of 3<br>
&lt;jensimmons> `grid-template-layout: 100px 1fr calc(2pi);`<br>
&lt;jensimmons> `grid-template-layout: 100px 1fr const(pi);`<br>
&lt;jensimmons> `grid-template-layout: 100px 1fr pi();`<br>
&lt;chris> 3 > 2 > 1<br>
&lt;emilio> 1<br>
&lt;RossenTheReal> option 1: 13 votes<br>
&lt;RossenTheReal> option 2: 3<br>
&lt;jensimmons> oh I wanted to vote for 2<br>
&lt;jensimmons> option 2: 2<br>
&lt;RossenTheReal> option 3: 5 vites<br>
&lt;bkardell_> TabAtkins: we will take the strawpoll as evidence for now and use option 1<br>
&lt;jensimmons> `grid-template-layout: 100px 1fr calc(2*pi);`<br>
&lt;TabAtkins> Chris: This'll let us close the long-running issue that 'rad' is useless without pi?<br>
&lt;TabAtkins> TabAtkins: Yes<br>
&lt;bkardell_> TabAtkins: final bits "stuff we probably don't want"... random ... seems impossible<br>
&lt;bkardell_> TabAtkins: clz32 -- it's... complicated<br>
&lt;bkardell_> myles: it's used in video codecs<br>
&lt;bkardell_> TabAtkins: which you probably shouldn't be doing in css<br>
&lt;bkardell_> tess: I love the idea of someone trying tho<br>
&lt;bkardell_> TabAtkins: last one is imul()<br>
&lt;bkardell_> chris: what is that for even<br>
&lt;bkardell_> TabAtkins: we don't want it<br>
&lt;bkardell_> TabAtkins:  pow with an e argument - I don't know if there is something here with speed<br>
&lt;bkardell_> fantasai: the pow function takes two args -- what if you give on?<br>
&lt;bkardell_> fantasai: the pow function takes two args -- what if you give one?<br>
&lt;bkardell_> TabAtkins: it would be invalid<br>
&lt;bkardell_> fantasai: maybe we should make it consistent with others?<br>
&lt;chris> make second argument to pow optional, defaulting to 1<br>
&lt;iank_> The other way to make it consistent is to not have the default arg for, log(), and add ln()<br>
&lt;fantasai> s/with others/with log by making it default to e/<br>
&lt;TabAtkins> Notes that exp(x) == pow(e, x)<br>
&lt;iank_> log(val, base), ln(val), pow(val, pow), exp(val)<br>
&lt;myles> TabAtkins: that isn't quite true to to precision (which CSS doesn't care about)<br>
&lt;chris> pow(foo) == pow(foo, 1) == foo<br>
&lt;myles> TabAtkins: but it's almost true!<br>
&lt;bkardell_> dbaron: so is anyone going to be annyoed by log in css being math log and not console log<br>
&lt;jfkthame> calculators I have known typically have a dedicated e^x key (=exp), although they also have x^y (=pow)<br>
&lt;bkardell_> fantasai: do you have a different suggestion dbaron ?<br>
&lt;bkardell_> dbaron: ln?<br>
&lt;fantasai> fantasai: for log of base 10?<br>
&lt;bkardell_> RossenTheReal:  any more comments or objections on adding these 5: abs, log, exp, and the two constants e and pi<br>
&lt;fantasai> s/constants/keyword constants/<br>
&lt;bkardell_> RESOLVED: add these 5 -  abs, log, exp, and the two constants e and pi<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4688#issuecomment-577120674 using your GitHub account

Received on Wednesday, 22 January 2020 10:41:24 UTC