[Python-Dev] Caching float(0.0)

Fredrik Lundh fredrik at pythonware.com
Tue Oct 3 10:32:07 CEST 2006

Terry Reedy wrote:

> For true floating point measurements (of temperature, for instance), 
> 'integral' measurements (which are an artifact of the scale used (degrees F 
> versus C versus K)) should generally be no more common than other realized 
> measurements.

a real-life sensor is of course where the 121.216 in my original post to 
this thread came from.

(note that most real-life sensors involve A/D conversion at some point, 
which means that they provide a limited number of discrete values.  but 
only the code dealing with the source data will be able to make any 
meaningful assumptions about those values.)

I still think it might make sense to special-case float("0.0") (padding, 
default values, etc) inside PyFloat_FromDouble, and possibly also 
float("1.0") (scale factors, unit vectors, normalized max values, etc) 
but everything else is just generalizing from random observations.

adding a few notes to the C API documentation won't hurt either, I 
suppose. (e.g. "note that each call to PyFloat_FromDouble may create a 
new floating point object; if you're converting data from some internal 
format to Python floats, it's often more efficient to map directly to 
preallocated shared PyFloat objects, instead of mapping first to float 
or double and then calling PyFloat_FromDouble on that value").


More information about the Python-Dev mailing list