Python-How to determine the largest / smallest int / long / float / complex numbers that my system can handle

Features: Python 3.3.1

What I was trying to do: "Using Python, determine the largest and smallest numbers, longest, floating and complex numbers that your system can handle.

What I did: I went through the Python math modules and all the built-in functions related to math and numbers, but couldn't find a way to do this. I also tried something like max(range(0,)) , but it returned a ValueError: max() arg is an empty sequence error ValueError: max() arg is an empty sequence .

Question: How do I determine the largest / smallest numbers int / long / float / complex with which my system can handle Python? As a newbie, I know that I must have missed something, but I tried and could not figure it out. I appreciate your help!

+6
source share
2 answers

The numerical limitations of python are available in the sys module , for example, any of them:

  • sys.float_info is a named floating point constraint tuple for your platform. Floating-point numbers consist of exponent and precision; you must be more precise about what you mean by the largest number here; the number with the highest score and the full accuracy of using sys.float_info.max .

  • sys.int_info ; not so much restrictions as implementation details; you should be able to evaluate the largest integer possible from this. Python integers are limited only by your available memory.

  • sys.maxsize ; platform word size and restriction of lists and tuples, etc.

So, for integers there is basically a soft limit on the maximum and minimum values. It depends on how much memory your process can use, and how much memory your process already uses for other purposes.

In Python 3, there is no longer a separate long type, but in Python 2 sys.maxsize + 1 should be long , as well as -sys.maxsize - 2 . Between these two extremes lies the range of possible β€œshort” integers.

For complex numbers, the ordering is a bit more .... anyway. Complex numbers have real and imaginary components, both are floats. Guess what? These are the python plugins, and you already have the limits information above:

 >>> type(1j) <type 'complex'> >>> type(1j.real) <type 'float'> >>> type(1j.imag) <type 'float'> 
+11
source

sys.float_info provides the required information for floating point values.

 >>> sys.float_info.max 1.7976931348623157e+308 

Python 3 has no upper or lower limits for integers and there is no mathematical definition for ordering arbitrary complex numbers (although the real or imaginary parts of two complex numbers can be ordered separately).

+4
source

Source: https://habr.com/ru/post/946855/


All Articles