<div dir="auto"><div>I do agree that a math.count_ulps() would be very nice to have. Or whatever spelling NumPy users for that concept.</div><div dir="auto"><br></div><div dir="auto">I see nextafter as more similar. Yes, it's not a uniform increment, which is the whole point. If you want a convergence that is as good as it can be in float, that's the relevant measure. Likewise for "almost as good" being N ulps.<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On Feb 24, 2017 9:43 PM, "Nathaniel Smith" <<a href="mailto:njs@pobox.com">njs@pobox.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div class="quoted-text"><div><div class="gmail_extra"><div class="gmail_quote">On Feb 24, 2017 5:29 PM, "David Mertz" <<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>> wrote:<br type="attribution"><blockquote class="m_-7828858540406077445quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Marc-André slightly misspelled the recent-ish addition of math.isclose(), but I agree that it is absolutely where a "nextafter" belongs.<div><br></div><div>The function signature is already relatively complex to cover several different but related use cases.  I.e.:</div><div><br></div><div>    is_close(a, b, *, rel_tol=1e-09, abs_tol=0.0) -> bool<br><div class="gmail_extra"><br></div><div class="gmail_extra">I think an additional keyword-only argument for `nextafter_tol` (maybe a different spelling) would fit very naturally there.  This would allow someone to specify 1 for that degree of closeness, but it would also allow them to specify some integer larger than 1 without needed to write a loop calling `nextafter()` repeatedly.</div></div></div></blockquote></div></div></div><div dir="auto"><br></div></div><div dir="auto">My 2c: I disagree -- numerical tolerance based closeness is fundamentally different than floating point representation based closeness (often discussed with the term "ulp" = "unit in the last place". For example, the number that's closest to 1.0 from above is twice as far away in numerical terms as the number that's closest to it from below. Mixing these two concepts in one function is just confusing, and we're not going to run out of names.</div><div dir="auto"><br></div><div dir="auto">It's also a little weird to jump from nextafter to isclose, since AFAIK they have pretty much non-overlapping use cases... </div><div dir="auto"><br></div><div dir="auto">FWIW, numpy provides all of the following as separate functions:</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">* an isclose equivalent</span><br></div><div dir="auto">* nextafter</div><div dir="auto">* a function for counting the number of ulps between two floats</div><div dir="auto">* a function for checking that two floats differ by at most N ulps</div><div dir="auto"><br></div><div dir="auto">I'm not enough of an expert on numerical analysis to have an opinion on how useful these would be for Python itself. They certainly are part of a complete IEEE754 implementation, and useful for exploring the details of how floats work, if nothing else.</div><font color="#888888"><div dir="auto"><br></div><div dir="auto">-n</div></font></div>
</blockquote></div><br></div></div></div>