Search code examples
pythonsys

What is the meaning of float(sys.maxsize)?


enter image description here

I’m studying about sys.maxsize .

As I know, sys.maxsize means largest “integer” value that py_ssize_t can store.

and I compared float(sys.maxsize) and sys.maxsize.

And I found there is difference between them which is point(.)

Even though I put sys.maxsize into float,

Doesn’t it has to be bigger than 9.22xxx?

Like float(922) is 922.0, Not 9.22

I want to know why float(sys.maxsize) gets smaller than sys.maxsize.

Thanks for the answers to my question, and hope you have a great day.


Solution

  • That point is caused by the fact that the __repr__ method of class float uses the scientific notation.

    Do you see that e+18 at the end? It means the number is the floated-point-number multiplied for 10 at the power of 18.


    If you don't want it to happen, simply avoid using float, or represent the float using numpy.format_float_positional.