Python Forum
float.hex() is one bit short
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
float.hex() is one bit short
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Is the last 1 bit for +/-?
Reply
#3
(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 '.'.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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?
Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Short code for EventGhost not working Patricia 8 3,584 Feb-09-2021, 07:49 PM
Last Post: Patricia
  How can I make a short-key in Spyder (Python IDE)? moose 3 2,620 Nov-02-2020, 12:13 PM
Last Post: jefsummers
  Short font question Pizzas391 9 3,217 Nov-27-2019, 05:57 PM
Last Post: ichabod801
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,322 Jul-25-2019, 11:32 PM
Last Post: scidam
  short way to combine tuples and int's Annie 6 4,488 Jun-16-2017, 02:35 AM
Last Post: Annie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020