Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; 'conversions': 0.07; 'differently': 0.07; 'formatting': 0.07; 'python': 0.09; 'forcing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rounding': 0.09; 'settings,': 0.09; '2.7': 0.13; '(like': 0.15; 'cases': 0.15; 'exponential': 0.16; 'fpu': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:String': 0.16; 'platforms': 0.18; 'example': 0.23; 'header:User-Agent:1': 0.26; 'common': 0.26; '(e.g.,': 0.27; '2.6': 0.27; 'format,': 0.27; 'header:X-Complaints-To:1': 0.28; 'writes:': 0.29; 'performing': 0.30; 'code': 0.31; 'platforms.': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'built-in': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'correctly': 0.37; 'uses': 0.37; '(for': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'different': 0.63; 'behavior': 0.64; 'results': 0.65; 'below.': 0.68; 'functions)': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Dickinson Subject: Re: Float to String Date: Wed, 31 Oct 2012 15:39:53 +0000 (UTC) References: <69712207-3e7c-4dc2-be36-9b1a94f34c24@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 213.1.240.227 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351698307 news.xs4all.nl 6847 [2001:888:2000:d::a6]:38588 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32527 3ds.com> writes: > When formatting a float using the exponential format, the rounding is > different in Python-2.6 and Python-2.7. See example below. Is this > intentional? Yes, in a sense. Python <= 2.6 uses the OS-provided functionality (e.g., the C library's strtod, dtoa and sprintf functions) to do float-to-string and string-to-float conversions, and hence behaves differently from platform to platform. In particular, it's common for near halfway cases (like the one you're looking at here) and tiny numbers to give different results on different platforms. Python >= 2.7 has its own built-in code for performing float-to-string and string-to-float conversions, so those conversions are platform- independent and always correctly rounded. (Nitpick: it's still theoretically possible for Python 2.7 to use the OS code if it can't determine the floating-point format, or if it can't find a way to ensure the proper FPU settings, but I don't know of any current platforms where that's the case.) > Is there any way of forcing the Python-2.6 behavior (for compatibility > reasons when testing)? Not easily, no. -- Mark