[BangPypers] A link I found today
Anand Chitipothu
anandology at gmail.com
Mon Oct 12 13:02:45 CEST 2009
On Mon, Oct 12, 2009 at 4:15 PM, Anand Balachandran Pillai
<abpillai at gmail.com> wrote:
>
>
> On Mon, Oct 12, 2009 at 4:08 PM, Rajeev J Sebastian
> <rajeev.sebastian at gmail.com> wrote:
>>
>>
>> > I am not however a fan of the decimal module since it uses strings as
>> > the
>> > base type.
>>
>> What else should it use then ?
>
> Nothing. It should be taken care of in the float implementation
> without needing another module to fix it.
>
> Having to convert my float to a string to get a correct representation of
> it
> is indeed awkward.
>
>>>> Decimal(1.0)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib64/python2.5/decimal.py", line 578, in __new__
> "First convert the float to a string")
> TypeError: Cannot convert float to Decimal. First convert the float to a
> string
>
> A strange error, but I agree it is required for the module to work...!
>
> Does numpy take care of these issues ?
The error message is wrong not the implementation. Floating point
representation is not exact. For example look at 1.1:
>>> 1.1
1.1000000000000001
If you say Decimal(1.1) should it take it as 1.1 or 1.1000000000000001?
More information about the BangPypers
mailing list