In the mathematical operations part of the spec, there's a reference to a floor function, specified in terms of subtraction and modulo in its note. There is no corresponding ceil function, but it could be similarly specified as ceil(x) = -floor(-x).
Is there a reason these aren't used for Math.ceil and Math.floor? Similarly, is there a reason why max and min aren't used for Math.max or Math.min, respectively?
floor is used in a number of places; where would we use this operation if defined?
I forgot to re-add a couple key details when I filed the bug. Fixed.
cc @allenwb; I'm assuming because it's tricky to talk about the boundaries between mathematical operations and the edge cases of JS number values (zeroes, infinities, NaN).
I think the Math.* algorithms could all use a little bit of cleanup because most non-implementation-defined algorithms are defined in prose, but they could be better and more clearly and precisely defined using algorithms.
Ones with algorithm-based definitions:
Math.clz32Math.froundMath.imulMath.pow, in terms of the implementation-defined ** operatorOnes that should have algorithm-based definitions:
Math.abs, in terms of the abs function specified in the specMath.ceil, in terms of the ceil function specified the initial commentMath.floor, in terms of the floor function specified in the specMath.max, in terms of the max function specified in the specMath.min, in terms of the min function specified in the specMath.round, through explicit comparisonsMath.sign, through explicit comparisonsMath.trunc, through explicit comparisonsI'm not touching things like Math.sin or Math.log1p, though: that's obviously implementation-defined stuff, and it's just easier to specify in prose with a few constraints.
These seem like reasonable editorial PRs to me.
The mathematical floor function and Math.floor are different things. One works on mathematical real numbers (which don't have infinities and signed zeroes), the other on IEEE doubles, so you still need special cases for 卤0, numbers between 0 and 1, etc. I suppose you could add several more rows to the table with the last one being the catchall "use the mathematical floor function".
Most helpful comment
The mathematical floor function and
Math.floorare different things. One works on mathematical real numbers (which don't have infinities and signed zeroes), the other on IEEE doubles, so you still need special cases for 卤0, numbers between 0 and 1, etc. I suppose you could add several more rows to the table with the last one being the catchall "use the mathematical floor function".