Python Forum
float.hex() is one bit short - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: float.hex() is one bit short (/thread-4143.html)



float.hex() is one bit short - Skaperen - Jul-26-2017

the float.hex() method produces output that shows 52 bits of precision, yet the float type as implemented on x86 (both 32 bit and 64 bit systems) has 53 bits of precision.  does anyone know of a way to get all 53 bits of a float in hexadecimal format?


RE: float.hex() is one bit short - nilamo - Jul-26-2017

Is the last 1 bit for +/-?


RE: float.hex() is one bit short - Skaperen - Jul-26-2017

(Jul-26-2017, 02:09 AM)nilamo Wrote: Is the last 1 bit for +/-?
i don't understand this question.

nevermind! i had it wrong. it is doing all 53 bits. i failed to count what it showed to the left of the '.'.


RE: float.hex() is one bit short - nilamo - Jul-26-2017

I assumed the underlying issue was similar to signed/unsigned ints, where one bit is used to keep track of whether or not the value is negative.

After actually looking, it appears I know almost nothing of floats, and will thus bow out of the conversation... https://stackoverflow.com/a/18409644
...good luck?


RE: float.hex() is one bit short - Skaperen - Jul-26-2017

well the whole point is moot. float.hex() produces sufficient output to represent the complete precision of a float value (same as a double in C) for the x86 architecture. i have not tested other architectures, yet. i counted only the digits to the right of the decimal point because i had been working with those in some code and my mind focused too tightly when checking that.

i should write some code that runs some float maths to discover that true precision (BTDT in C (and asm for x86, Sparc, and S/370) and found a gcc bug many years ago when doing that) instead of using the implementation architecture configuration.