A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/068481.html below:

Rounding error

Rounding errorD-Man dsh8290 at rit.edu
Wed Apr 4 18:16:31 EDT 2001
On Thu, Apr 05, 2001 at 09:58:05AM +1200, Matthew wrote:
| Hi,
| 
| I'm calculating a bunch of co-ordinates as below. I'm using
| Round(<coord>,2) but as you can see rounding errors are happening...

| How do I overcome this? I'm using ActivePython Build203.

Don't use FP.  Floating point is inherently inaccurate.  You said they
are co-ordinates,  2-d or 3-d?  I would recommend creating a Point
class, something along the lines of:

class Point :
    def __init__( xn , xd , yn , yd ) :
       self.xn = xn
       self.xd = xd
       self.yn = yn
       self.yd = yd

    ...


where xn is the integer part and xd is the decimal part.  Both should
be integers.  Do the rounding yourself on the [xy]d parts if you
really want it rounded (mod 100 should work for that, but check for
overflow and handle it properly).

HTH,
-D



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4