[Tutor] Need a better name for this function
Richard D. Moores
rdmoores at gmail.com
Wed Dec 16 05:12:16 CET 2009
On Tue, Dec 15, 2009 at 19:32, Dave Angel <davea at ieee.org> wrote:
>
> Richard D. Moores wrote:
>>
>> On Tue, Dec 15, 2009 at 15:05, Dave Angel <davea at ieee.org> wrote:
>>
>>>
>>> Richard D. Moores wrote:
>
> <snip>
>>
>> If I keep the function, renamed to Allan's suggested float2Decimal(),
>> then that's all I'll have to remember. But I see yours and Hugo's
>> point.
>>
>>
>
> Just remember, if the entire body of the function is just a call to the other one, all you need is an assignment. It'll go faster, too. So whatever you decide to call it, you just need something like:
> float2Decimal = decimal.Decimal.from_float
>>>
>>> As for the name being too long, the real question is what's the purpose of the function.
>>>
>>
>> I don't know if it will be useful or not, but it will satisfy my
>> curiosity, given a float, as to what the "exact number stored in my
>> computer is".
>>
>>
>
> But it doesn't do that. I'll try to elaborate below.
Before I can go below I need to know if you are saying that the
relevant doc is wrong. I took the original name for my function almost
directly from it. Near the bottom of
<http://docs.python.org/3.1/tutorial/floatingpoint.html#representation-error>
we find "meaning that the exact number stored in the computer is equal
to the decimal value
0.1000000000000000055511151231257827021181583404541015625." And
coincidence or no, that's precisely what float2Decimal() returns for
0.1 .
Thanks,
Dick
More information about the Tutor
mailing list