Skip to content

Commit

Permalink
Editorial: side effects before returning in Math.{hypot,max,min}
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Sep 12, 2020
1 parent fb2811b commit 464d064
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -27834,15 +27834,16 @@ <h1>Math.hypot ( _value1_, _value2_, ..._values_ )</h1>
<p>Returns the square root of the sum of squares of its arguments.</p>
<p>When the `Math.hypot` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:</p>
<emu-alg>
1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _args_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _coerced_ be a new empty List.
1. Let _onlyZero_ be *true*.
1. For each element _number_ of _numbers_, do
1. Let _n_ be ? ToNumber(_number_).
1. If _n_ is *NaN* or _n_ is *+&infin;*, return _n_.
1. If _n_ is *-&infin;*, return *+&infin;*.
1. If _n_ is neither *+0* nor *-0*, set _onlyZero_ to *false*.
1. For each element _arg_ of _args_, do
1. Let _n_ be ? ToNumber(_arg_).
1. Append _n_ to _coerced_.
1. Let _onlyZero_ be *true*.
1. For each element _number_ of _coerced_, do
1. If _number_ is *NaN* or _number_ is *+&infin;*, return _number_.
1. If _number_ is *-&infin;*, return *+&infin;*.
1. If _number_ is neither *+0* nor *-0*, set _onlyZero_ to *false*.
1. If _onlyZero_ is *true*, return *+0*.
1. Return an implementation-approximated value representing the square root of the sum of squares of the elements of _coerced_.
</emu-alg>
Expand Down Expand Up @@ -27922,13 +27923,16 @@ <h1>Math.max ( _value1_, _value2_, ..._values_ )</h1>
<p>Given zero or more arguments, calls ToNumber on each of the arguments and returns the largest of the resulting values.</p>
<p>When the `Math.max` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:</p>
<emu-alg>
1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _args_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _coerced_ be a new empty List.
1. For each element _arg_ of _args_, do
1. Let _n_ be ? ToNumber(_arg_).
1. Append _n_ to _coerced_.
1. Let _highest_ be *-&infin;*.
1. For each element _number_ of _numbers_, do
1. Let _n_ be ? ToNumber(_number_).
1. If _n_ is *NaN*, return *NaN*.
1. If _n_ is *+0* and _highest_ is *-0*, set _highest_ to *+0*.
1. If _n_ &gt; _highest_, set _highest_ to _n_.
1. For each element _number_ of _coerced_, do
1. If _number_ is *NaN*, return *NaN*.
1. If _number_ is *+0* and _highest_ is *-0*, set _highest_ to *+0*.
1. If _number_ &gt; _highest_, set _highest_ to _number_.
1. Return _highest_.
</emu-alg>
<emu-note>
Expand All @@ -27941,13 +27945,16 @@ <h1>Math.min ( _value1_, _value2_, ..._values_ )</h1>
<p>Given zero or more arguments, calls ToNumber on each of the arguments and returns the smallest of the resulting values.</p>
<p>When the `Math.min` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:</p>
<emu-alg>
1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _args_ be a List containing _value1_, _value2_, and the elements of _values_ in List order.
1. Let _coerced_ be a new empty List.
1. For each element _arg_ of _args_, do
1. Let _n_ be ? ToNumber(_arg_).
1. Append _n_ to _coerced_.
1. Let _lowest_ be *+&infin;*.
1. For each element _number_ of _numbers_, do
1. Let _n_ be ? ToNumber(_number_).
1. If _n_ is *NaN*, return *NaN*.
1. If _n_ is *-0* and _lowest_ is *+0*, set _lowest_ to *-0*.
1. If _n_ &lt; _lowest_, set _lowest_ to _n_.
1. For each element _number_ of _coerced_, do
1. If _number_ is *NaN*, return *NaN*.
1. If _number_ is *-0* and _lowest_ is *+0*, set _lowest_ to *-0*.
1. If _number_ &lt; _lowest_, set _lowest_ to _number_.
1. Return _lowest_.
</emu-alg>
<emu-note>
Expand Down

0 comments on commit 464d064

Please sign in to comment.