accuracy problem in calculation
rosuav at gmail.com
Thu Nov 8 18:13:33 CET 2012
On Fri, Nov 9, 2012 at 4:05 AM, Debashish Saha <silideba at gmail.com> wrote:
> Out: 2.384185791015625e-07
> Out: 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).
> so my question is how to increase the accuracy(windows7(32bit)
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, 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.
>>> from decimal import Decimal
Unless something's tying you to Python 2, consider moving to Python 3.
You may find that, on Python 3.3, you can switch to Decimal without
losing too much performance.
More information about the Python-list