On Wed, May 21, 2008 at 4:34 PM, Dave Parker
<[EMAIL PROTECTED]> wrote:
> On May 21, 12:38 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
>
>> >>> a+0.999     # gives expected result
>> 9999999999999998.0
>> >>> a+0.9999   # doesn't round correctly.
>>
>> 10000000000000000.0
>
> Shouldn't both of them give 9999999999999999.0?

My understand is no, not if you're using IEEE floating point.

> I wrote the same program under Flaming Thunder:
>
>     Set a to 10^16-2.0.
>     Writeline a+0.999.
>     Writeline a+0.9999.
>
> and got:
>
>     9999999999999998.999
>     9999999999999998.9999

You can get the same results by using python's decimal module, like this:
>>> from decimal import Decimal
>>> a = Decimal("1e16")-2
>>> a
Decimal("9999999999999998")
>>> a+Decimal("0.999")
Decimal("9999999999999998.999")
>>> a+Decimal("0.9999")
Decimal("9999999999999998.9999")
>>>

-- 
Jerry
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to