Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70284 > unrolled thread

Re: Simple question

Started byTim Chase <python.list@tim.thechases.com>
First post2014-04-15 13:33 -0500
Last post2014-04-15 13:33 -0500
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.


Contents

  Re: Simple question Tim Chase <python.list@tim.thechases.com> - 2014-04-15 13:33 -0500

#70284 — Re: Simple question

FromTim Chase <python.list@tim.thechases.com>
Date2014-04-15 13:33 -0500
SubjectRe: Simple question
Message-ID<mailman.9289.1397586829.18130.python-list@python.org>
On 2014-04-15 19:18, Phil Dobbin wrote:
> I'm confused as to this part:
> 
> '>>> 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?

You omit one key detail in your "....", the "e-17" which means that
is 5.55111... times 10^-17 which is a REALLY small number.  To
better show that, have it formatted to place:

  >>> "%55.55f" % (0.1 + 0.1 + 0.1 - 0.3)
  '0.0000000000000000555111512312578270211815834045410156250'

For most engineering purposes, that's effectively zero.

It comes about because of how floating-point numbers are represented
internally.  You can read a lot more than anybody should want to
know at [1].  By using the Decimal module, you remove some of that
imprecision.

-tkc

[1] http://en.wikipedia.org/wiki/Ieee_float




[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web