Movatterモバイル変換
[0]ホーム
[Python-ideas] math.nextafter
Nathaniel Smithnjs at pobox.com
Fri Feb 24 21:43:01 EST 2017
On Feb 24, 2017 5:29 PM, "David Mertz" <mertz at gnosis.cx> wrote:Marc-André slightly misspelled the recent-ish addition of math.isclose(),but I agree that it is absolutely where a "nextafter" belongs.The function signature is already relatively complex to cover severaldifferent but related use cases. I.e.: is_close(a, b, *, rel_tol=1e-09, abs_tol=0.0) -> boolI think an additional keyword-only argument for `nextafter_tol` (maybe adifferent spelling) would fit very naturally there. This would allowsomeone to specify 1 for that degree of closeness, but it would also allowthem to specify some integer larger than 1 without needed to write a loopcalling `nextafter()` repeatedly.My 2c: I disagree -- numerical tolerance based closeness is fundamentallydifferent than floating point representation based closeness (oftendiscussed with the term "ulp" = "unit in the last place". For example, thenumber that's closest to 1.0 from above is twice as far away in numericalterms as the number that's closest to it from below. Mixing these twoconcepts in one function is just confusing, and we're not going to run outof names.It's also a little weird to jump from nextafter to isclose, since AFAIKthey have pretty much non-overlapping use cases...FWIW, numpy provides all of the following as separate functions:* an isclose equivalent* nextafter* a function for counting the number of ulps between two floats* a function for checking that two floats differ by at most N ulpsI'm not enough of an expert on numerical analysis to have an opinion on howuseful these would be for Python itself. They certainly are part of acomplete IEEE754 implementation, and useful for exploring the details ofhow floats work, if nothing else.-n-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170224/aea17b8e/attachment.html>
More information about the Python-ideasmailing list
[8]ページ先頭