Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70282
| Date | 2014-04-15 19:31 +0100 |
|---|---|
| From | Phil Dobbin <phildobbin@gmail.com> |
| Organization | Horse Latitudes Ltd |
| Subject | Re: Simple question |
| References | <534D7807.6050408@gmail.com> <CAKJDb-PBn7PquDEuQOdjC7R81JG6p=nnBjEr70=MeU9Mcv9GNg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9288.1397586705.18130.python-list@python.org> (permalink) |
On 15/04/2014 19:25, Zachary Ware wrote:
> On Tue, Apr 15, 2014 at 1:18 PM, Phil Dobbin <phildobbin@gmail.com> wrote:
>> Hi, all.
>>
>> I've just started to learn Python (I'm reading Mark Lutz's 'Learning
>> Python' from O'Reilly) & I'm confused as to this part:
>>
>> '>>> 0.1 + 0.1 + 0.1 - 0.3
>> 5.55111.....'
>>
>> Using 'import Decimal' you can get a much closer result i.e.
>> 'Decimal('0.0')'
>>
>> What I'm wondering is why the first calculation that arrives at
>> '5.55111...' is so far out?
>
> First, note that the "..." part of "5.55111..." is very important
> here, it's actually "5.55111...e-17" which means it's really
> approximately 0.000000000000000055111, which is really very close to
> the answer you'd expect from a human. To learn more about why Python
> doesn't give 0.0, read this:
> https://docs.python.org/3/tutorial/floatingpoint.html
>
> Hope this helps,
>
Hi, Zach.
I saw the 'e-17' appended to the end but was unsure of its meaning (
quite a number of things are introduced in the book with clarification
of their meaning not forthcoming 'til later on).
Thank you for the link. It'll be very helpful.
Cheers,
Phil...
--
currently (ab)using
CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard,
RHEL 7, Ubuntu Precise & Saucy
GnuGPG Key : http://phildobbin.org/publickey.asc
Based in London, UK
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Simple question Phil Dobbin <phildobbin@gmail.com> - 2014-04-15 19:31 +0100
csiph-web