[Python-ideas] Hexadecimal floating literals

Antoine Pitrou solipsis at pitrou.net
Fri Sep 22 05:42:12 EDT 2017


On Thu, 21 Sep 2017 22:14:27 -0500
Tim Peters <tim.peters at gmail.com> wrote:
> [David Mertz <mertz at gnosis.cx>]
> > -1
> >
> > Writing a floating point literal requires A LOT more knowledge than writing
> > a hex integer.  
> 
> But not really more than writing a decimal float literal in
> "scientific notation".  People who use floats are used to the latter.
> Besides using "p" instead of "e" to mark the exponent, the only
> differences are that the mantissa is expressed in hex instead of in
> decimal, and the implicit base to which the exponent is applied is 2
> instead of 10.

The main difference is familiarity.  "scientific" notation should be
well-known and understood even by high school kids.  Who knows about
hexadecimal notation for floats, apart from floating-point experts?

So for someone reading code, the scientific notation poses no problem
as they understand it intuitively (even if they may not grasp the
difficulties of the underlying conversion to binary FP), while for
hexadecimal float notation need they have to go out of their way to
learn about it, parse the number slowly and try to make out what its
value is.

Regards

Antoine.




More information about the Python-ideas mailing list