How to check the size of a float in python?

前端 未结 5 1181
感动是毒
感动是毒 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 08:59

    python -c "import sys,math; print(sys.float_info.mant_dig + math.ceil(math.log2(sys.float_info.max_10_exp - sys.float_info.min_10_exp)) + 1)"

    "+1" because one digit in the mantissa is stored implicitly.

提交回复
热议问题