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?">

(original) (raw)

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 "", line 1, in

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@sixty-north.com | T +47 63 01 04 44 | M +47 924 30 350

On 22 March 2018 at 10:51, Kirill Balunov <kirillbalunov@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 \`as\_integer\_ratio\` discussion.

With kind regards,
-gdg


\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/rob%40sixty-north.com