[Tutor] Need a better name for this function
Richard D. Moores
rdmoores at gmail.com
Wed Dec 16 09:44:36 CET 2009
On Tue, Dec 15, 2009 at 23:30, Hugo Arts <hugo.yoshi at gmail.com> wrote:
> On Wed, Dec 16, 2009 at 5:12 AM, Richard D. Moores <rdmoores at gmail.com> wrote:
>>
>> 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 .
>>
>
> The docs are right. The function will give you the exact value of any
> floating point number stored in memory.
OK!
> I think what Dave is trying to
> say is that if you want to store the exact value 0.1 on your computer,
> this function won't help you do that.
Yes, I knew that.
> It also won't help you avoid any
> kinds of rounding errors, which is worth mentioning. If you want 0.1
> represented exactly you'll need to use the Decimal module all the way
> and avoid floating point entirely.
>
> Of course, if all you want is to get a better understanding of what's
> actually stored on your computer when you try to store 0.1 in a float,
> this can be a useful tool.
Yes, that's what I wanted the function for, and with a name that would
be easy to remember.
> I also recommend the article "What Every
> Computer Scientist Should Know About Floating-point Arithmetic." It's
> a very detailed explanation, though somewhat technical:
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
I'm sleepy now, but will dig into it tomorrow.
Thanks for your help, Hugo.
Dick
More information about the Tutor
mailing list