Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70279 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-04-16 04:27 +1000 |
| Last post | 2014-04-16 04:27 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Simple question Chris Angelico <rosuav@gmail.com> - 2014-04-16 04:27 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-04-16 04:27 +1000 |
| Subject | Re: Simple question |
| Message-ID | <mailman.9285.1397586432.18130.python-list@python.org> |
On Wed, Apr 16, 2014 at 4:18 AM, Phil Dobbin <phildobbin@gmail.com> wrote: > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? There's something you're not seeing here. In full, the output I see is: >>> 0.1 + 0.1 + 0.1 - 0.3 5.551115123125783e-17 See that bit at the end? "e-17" means "times ten to the -17th power" - that is, move the decimal point 17 places to the left. So the actual value is: >>> "%50.50f"%(0.1 + 0.1 + 0.1 - 0.3) '0.00000000000000005551115123125782702118158340454102' It's not actually as far out as you think; in fact, that's incredibly close to zero. A full explanation of why floating point arithmetic does this can be found in many places on the internet, but the main thing to note is that it really isn't showing 5.5. ChrisA
Back to top | Article view | comp.lang.python
csiph-web