How to check the size of a float in python?

前端 未结 5 1191
感动是毒
感动是毒 2020-12-17 08:41

I want to check whether a float is actually 32 or 64bits (and the number of bits of a numpy float array). There should be a built-in, but just didn\'t find out...

5条回答
  •  生来不讨喜
    2020-12-17 09:08

    The range of floating point values is available in the sys.float_info object.

    As Sven says, for CPython float is always 64-bit. But Python's language reference says

    You are at the mercy of the underlying machine architecture (and C or Java implementation) for the accepted range ...".

    So this is not necessarily the case for other Python implementations.

提交回复
热议问题