[Python-Dev] Caching float(0.0)

Nick Maclaren nmm1 at cus.cam.ac.uk
Fri Sep 29 20:03:42 CEST 2006

"Jason Orendorff" <jason.orendorff at gmail.com> wrote:
> Anyway, this kind of static analysis is probably more entertaining
> than relevant.  ...

Well, yes.  One can tell that by the piffling little counts being
bandied about!  More seriously, yes, it is Well Known that 0.0 is
the Most Common Floating-Point Number is most numerical codes; a
lot of older (and perhaps modern) sparse matrix algorithms use that
to save space.

In the software floating-point that I have started to draft some
example code but have had to shelve (no, I haven't forgotten) the
values I predefine are Invalid, Missing, True Zero and Approximate
Zero.  The infinities and infinitesimals (a.k.a. signed zeroes)
could also be included, but are less common and more complicated.
And so could common integers and fractions.

It is generally NOT worth doing a cache lookup for genuinely
numerical code, as the common cases that are not the above rarely
account for enough of the numbers to be worth it.  I did a fair
amount of investigation looking for compressibility at one time,
and that conclusion jumped out at me.

The exact best choice depends entirely on what you are doing.

Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

More information about the Python-Dev mailing list