[Python-Dev] re: %b format (no, really)
Fri, 8 Jun 2001 13:21:10 -0400
> Why bother with floats at all?
> For teaching purposes, which is what started me on this
> in the first place --- I would like an easy way to show
> people the bit patterns corresponding to basic types.
I'm confused by this: while for integers the bits correspond very clearly
to what's stored in the machine, if you separate the mantissa and exponent
for floats the result won't "look like" the storage at all. Please give an
example first, like what do you intend to produce for
print "%b" % 0.1
print "%b" % -42e300
? You have to make decisions about whether or not to unbias the exponent
for display (if you don't, it's incomprehensible; if you do, it's not really
what's stored); whether or not to materialize the implicit most-significant
mantissa bit in 754 normalized values (pretty much ditto); and what to do
about Infs, NaNs, signed zeroes and denormal numbers.
The kicker is that, to be truly useful for teaching floats, you need a way
to select among all combinations of "yes" and "no" for each such decision.
A single fixed set of answers will confound more than clarify; e.g., it's
important to know what the "true exponent" is, but also to know what biased
exponents look like inside the box. This is too much for %b -- write a
float-format module instead.