[Python-Dev] Deprecating float.is_integer() (original) (raw)
Robert Smallshire rob at sixty-north.com
Thu Mar 22 12:42:17 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 ]
In the PR which implements is_integer() for int, the numeric tower, and Decimal I elected not to implement it for Complex or complex. This was principally because complex instances, even if they have an integral real value, are not convertible to int and it seems reasonable to me that any number for which is_integer() returns True should be convertible to int successfully, and without loss of information.
int(complex(2, 0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to int
There could be an argument that a putative complex.is_integral() should therefore return False, but I expect that would get even less support than the other suggestions in these threads.
*Robert Smallshire | *Managing Director Sixty North | Applications | Consulting | Training rob at sixty-north.com | T +47 63 01 04 44 | M +47 924 30 350 http://sixty-north.com
On 22 March 2018 at 10:51, Kirill Balunov <kirillbalunov at gmail.com> wrote:
I apologize that I get into the discussion. Obviously in some situations it will be useful to check that a floating-point number is integral, but from the examples given it is clear that they are very rare. Why the variant with the inclusion of this functionality into the math module was not considered at all. If the answer is - consistency upon the numeric tower - will it go for complex type and what will it mean (there can be two point of views)?
Is this functionality so often used and practical to be a method of float, int, ..., and not just to be an auxiliary function? p.s.: The same thoughts about
asintegerratio
discussion. With kind regards, -gdg
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ rob%40sixty-north.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180322/90a8b8f3/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 ]