question about cx_Oracle .thanks

Steve Holden sholden at holdenweb.com
Sat Jun 26 01:02:36 EDT 2004


Peter Hansen wrote:
[...]

> Since it has a limited number of binary digits available, it can't
> store precisely 42055.66, so 42055.6600000whatever is the next
> closest.  To demonstrate, the nearest neighbours that can be
> represented accurately are these (binary value one higher or lower):
> 
>  >>> struct.unpack('>d', binascii.unhexlify('40e488f51eb851ed'))
> (42055.660000000011,)
>  >>> struct.unpack('>d', binascii.unhexlify('40e488f51eb851eb'))
> (42055.659999999996,)
> 
> So clearly the binary can capture only increments of about
> 0.000000000007 or 0.000000000008 at a time, and all of these
> values must be treated as approximations... unless one was
> trying to store 42055.660000000003 in the first place!
> 
Just to make things even more complicated, of course, we must also 
remember that the delta between two adjacent floating-point numbers 
isn't constant, but will vary according to the magnitude of the numbers.

>> - this is an accurate decimal representation of the binary value:
>>
>>  >>> print repr(42055.66)
>> 42055.660000000003
> 
> 
> All very true. ;-)
> 
And it just goes to show that floating-point is quite confusing enough 
to make many a beginner run away in fright!

regards
  Steve




More information about the Python-list mailing list