<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 2, 2016 at 11:45 AM, Random832 <span dir="ltr"><<a href="mailto:random832@fastmail.com" target="_blank">random832@fastmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sure, but what the standard doesn't say is exactly what sequence of<br>
comparisons is entailed by a clamp function.<br>
<br>
def clamp(x, a, b):<br>
if x < a: return a<br>
else:<br>
if x > b: return b<br>
else: return x<br>
<br>
def clamp(x, a, b):<br>
if a <= x:<br>
if x <= b: return x<br>
else: return b<br>
else: return a<br>
<br>
There are, technically, eight possible naive implementations, varying<br>
along three axes:<br>
</blockquote><div><br></div><div>Exactly-- I thought this was self evident, but apparently not -- thanks for spelling it out.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">All such functions are equivalent if {a, b, x} is a set over which the<br>
relational operators define a total ordering, and a <= b. However, this<br>
is not the case if NaN is used for any of the arguments.<br>
<div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>Exactly again -- NaN's are kind of a pain :-(</div><div><br></div><div>As for the convert to floats issue -- correctness is more important than performance, and performance is probably most important for the special case of all floats. (or floats and integers, I suppose) -- i'm sure we can find a solution. LIkely something iike the second option above would work fine, and also work for anything with an ordinary total ordering.</div><div><br></div><div>-Chris</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>