
On Tue, Feb 8, 2022 at 2:25 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Mon, Feb 07, 2022 at 05:35:17PM -0800, Gregory P. Smith wrote:
CPython: yes. we use a double. Python the language: no. (float is single precision on many micropython platforms as it saves precious ram and performance, plus microcontroller fpu hardware like an M4 is usually single precision 32bit)
If we are to *officially* support non-double floats, it would be nice if sys.float_info were to tell us explicitly how wide the floats are rather than having to try to reverse engineer it from the other information there.
A floating point expert can probably look at this:
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
and immediately recognise that those values imply a 64-bit float, but I expect most people will not. If Python the language is going to support single, double, quad precision floats, and maybe even minifloats with just 16 or even fewer bits, then can we please add a field to float_info telling us how many bits the floats have?
There is no need to know how many bits it is. The meaningful information about precision and accuracy from a math point of view is already expressed in float_info. the size in bits isn't relevant. You can derive the size from that if you'd like and are willing to assume a binary format. binary_bits = ~mant_dig+log2(max_exp)... But that tells you less than sys.float_info. -gps