<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 4, 2016 at 5:35 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The IEEE 754 standard tells us what min(x, NAN) and max(x, NAN) should<br>
be: in both cases it is x.<br>
<br>
<a href="https://en.wikipedia.org/wiki/IEEE_754_revision#min_and_max" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/<wbr>IEEE_754_revision#min_and_max</a></blockquote><div><br></div><div>I thought an earlier post said something about a alternatvie min and max? -- but anyway, consisetncy with min and max is a pretty good argument. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Quote:<br>
<br>
For instance max{x, y} should deliver the same result as max{y, x} but<br>
almost no implementations do that when x is NaN. There are good<br>
reasons to define max{NaN, 5} := max{5, NaN} := 5 though many would<br>
disagree.<br></blockquote><div><br></div><div>I don't disagree that there are good reason, just that it's the final way to go :-) -- but if Kahan equivocates, then there isn't one way to go :-)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">As you propose it, clamp() is no use to me: it unnecessarily converts the<br>
bounds to float, which may raise an exception.</blockquote><div><br></div><div>no it doesn't -- that's only one way to implement it. We really should decide on the behaviour we want, and then figure out how to implemt it -- not choose something because it's easier to implement.</div><div><br></div><div>there was an earlier post with an implementation that would give the NaN-poising behaviour, but would also work with any total-ordered type as well. not that's thought about possible edge cases.</div><div><br></div><div><br></div><div>I think this is it:</div><div><br></div><div><span style="font-size:12.8px">def clamp(x, a, b):</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if a <= x:</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if x <= b: return x</span><br style="font-size:12.8px"><span style="font-size:12.8px"> else: return b</span><br style="font-size:12.8px"><span style="font-size:12.8px"> else: return a</span><br></div><div><br></div><div>hmm -- doesn't work for x is NaN, but limits are not -- but I'm sure that could be worked out.</div><div><br></div><div>
<p class=""><span class="">In [</span><span class=""><b>32</b></span><span class="">]: </span><span class="">clamp(nan, </span><span class="">0</span><span class="">, </span><span class="">100</span><span class="">)</span></p>
<p class=""><span class="">Out[</span><span class=""><b>32</b></span><span class="">]: </span><span class="">0</span></p></div><div><br></div><div>-CHB</div><div><br></div><div><br></div></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>