Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: accuracy problem in calculation Date: Thu, 8 Nov 2012 18:17:48 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 42 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1352398668 21640 64.122.56.22 (8 Nov 2012 18:17:48 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 8 Nov 2012 18:17:48 +0000 (UTC) User-Agent: slrn/pre1.0.0-18 (Linux) X-Received-Bytes: 2362 Xref: csiph.com comp.lang.python:32969 On 2012-11-08, Chris Angelico wrote: > On Fri, Nov 9, 2012 at 4:05 AM, Debashish Saha wrote: >> (1500000000+1.00067968)-(1500000000+1.00067961) >> Out[102]: 2.384185791015625e-07 >> >> 1.00067968-(1.00067961) >> Out[103]: 7.000000001866624e-08 >> >> above i am showing the two different results,though the two outputs >> should be same if we do it in copy (the lass one is acceptable value). Then do it the way you did the last one. Seriously, that's the answer they teach you in numerical analysis classes. >> so my question is how to increase the accuracy(windows7(32bit) >> ,python2.7.2) > > Welcome to floating point. You're working with very large and very > small numbers, and you _will_ lose accuracy. > > There are a few options. It's possible that a 64-bit build of Python > will give you more accuracy, Pretty doubtful. 64-bit and 32-bit builds on all common OSes and hardware are both going to use 64-bit IEEE floating point. > but better would be to separate your huge numbers from your tiny ones > and work with them separately. > Alternatively, switch to the Decimal or Fraction types, but be aware > that your script will probably run a lot slower. Or admit to yourself that the measurements that produce your input data just aren't that accurate anyway and forget about it. :) -- Grant Edwards grant.b.edwards Yow! Bo Derek ruined at my life! gmail.com