[Python-Dev] Caching float(0.0)

Steve Holden steve at holdenweb.com
Sat Sep 30 09:45:03 CEST 2006


Jason Orendorff wrote:
> On 9/29/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
> 
>>(I just checked the program I'm working on, and my analysis tells me
>>that the most common floating point value in that program is 121.216,
>>which occurs 32 times.  from what I can tell, 0.0 isn't used at all.)
> 
> 
> *bemused look*  Fredrik, can you share the reason why this number
> occurs 32 times in this program?  I don't mean to imply anything by
> that; it just sounds like it might be a fun story.  :)
> 
> Anyway, this kind of static analysis is probably more entertaining
> than relevant.  For your enjoyment, the most-used float literals in
> python25\Lib, omitting test directories, are:
> 
> 1e-006: 5 hits
> 4.0: 6 hits
> 0.05: 7 hits
> 6.0: 8 hits
> 0.5: 13 hits
> 2.0: 25 hits
> 0.0: 36 hits
> 1.0: 62 hits
> 
> There are two hits each for -1.0 and -0.5.
> 
> In my own Python code, I don't even have enough float literals to bother with.
> 
By these statistics I think the answer to the original question is 
clearly "no" in the general case.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden



More information about the Python-Dev mailing list