duncan smith wrote: > Christian Heimes wrote: >> duncan smith wrote: >>> Hello, >>> I'm trying to find a clean and reliable way of uncovering >>> information about 'extremal' values for floats on versions of Python >>> earlier than 2.6 (just 2.5 actually). I don't want to add a >>> dependence on 3rd party modules just for this purpose. e.g. For the >>> smallest positive float I'm using, >>> >>> >>> import platform >>> if platform.architecture()[0].startswith('64'): >>> TINY = 2.2250738585072014e-308 >>> else: >>> TINY = 1.1754943508222875e-38 >>> >>> >>> where I've extracted the values for TINY from numpy in IDLE, >>> >>> >>> >>> float(numpy.finfo(numpy.float32).tiny) >>> 1.1754943508222875e-38 >>> >>> float(numpy.finfo(numpy.float64).tiny) >>> 2.2250738585072014e-308 >> >> You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's >> float type is build upon C's double precision float type on both 32 and >> 64 bit builds. The simple precision 32bit float type isn't used. The >> DBL_MIN and DBL_MAX values are equal on all platforms that have full >> IEEE 754 float point support. The radix may be different, though. >> >> Christian > > OK, this is the sort of confusion I suspected. I wasn't thinking > straight. The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. > Whether this is relevant or not I can't say, but you must be careful to note that the smallest representable floating-point value (i.e. the smallest number distinguishable from zero) is not the same as the smallest difference between two numbers of a given magnitude.
Consider a decimal floating-point system with a two-digit exponent and a four-digit mantissa, and for convenience ignore negative mantissas. The range of representable non-zero values runs from 1E-99 to 9999E99. But adding 1E-99 to (say) 1 will just give you 1 because the system has insufficient precision to represent the true result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list