[Python-Dev] Deprecating float.is_integer() (original) (raw)
Chris Barker chris.barker at noaa.gov
Wed Mar 21 21:27:25 EDT 2018
- Previous message (by thread): [Python-Dev] Deprecating float.is_integer()
- Next message (by thread): [Python-Dev] Deprecating float.is_integer()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Mar 21, 2018 at 11:43 PM, Tim Peters <tim.peters at gmail.com> wrote:
Note: this is a top-posted essay much more about floating-point philosophy than about details. Details follow from the philosophy, and if philosophies don't match the desired details will never match either.
but of course :-)
From that fundamental "take floats exactly at face value" view, what .isinteger() should do for floats is utterly obvious:
sure -- but I don't think anyone is arguing that -- the question is whether the function should exist -- and that means not "how should it work?" or "is it clearly and appropriately defined?" but rather, "is it the "right" thing to do in most cases, when deployed by folks that haven't thought deeply about floating point.
Whether that's useful to you depends on the application you're
writing at the time.
exactly.
I think pretty much all the real world code that's been shown here for using .is_integer() is really about type errors (issues). The function at hand really wants integer inputs -- but wants to allow the user to be sloppy and provide a float type that happens to be an int. Given Python's duck-typing nature, maybe that's a good thing? I know I really discourage dynamic type checking....
Also, every example has been for small-ish integers -- exponents, factorials, etc -- not order 1e300 -- or inf or NaN, etc.
Finally, the use-cases where the value that happens-to-be-an-int is computed via floating point -- .is_integer() is probably the wrong check -- you probably want isclose().
The other use-cases: and floor() and ceil() and round() all produce actual integers -- so no need for that anymore.
All this points to: we don't need .is_integer
All the being said -- the standard for depreciation is much higher bar than not-adding-it-in-the-first-place.
-CHB
--
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180322/34377bbc/attachment.html>
- Previous message (by thread): [Python-Dev] Deprecating float.is_integer()
- Next message (by thread): [Python-Dev] Deprecating float.is_integer()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]