Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'handler': 0.04; 'exception.': 0.07; 'python': 0.09; 'integers': 0.09; 'meaningful': 0.09; 'option:': 0.09; 'zero.': 0.09; 'aug': 0.13; 'exceptions.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer.': 0.16; 'integers,': 0.16; 'nan': 0.16; 'subject:arithmetic': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'thanks,': 0.18; 'sort': 0.21; 'received:209.85.214.174': 0.21; '(on': 0.22; "python's": 0.23; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'compiled': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'division': 0.29; "i'm": 0.29; 'point': 0.31; 'url:python': 0.32; 'point,': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'enough': 0.36; 'possible': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'url:docs': 0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'most': 0.61; 'divide': 0.84; 'nagy': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=cMpBQozva1SdMshYieqyq78uUa1O8D0aAzE2xmy9HSg=; b=XYBGRukBGaUiqNyP8pocEtKAK9QlL6wA3T1v0L3WdK1sNDgBHg5jktA6MceMxnn9uq omlnFa7aWrt1Ncrct0hET+MLe43eMkQyqM1OKuO86WDTMx6sqvgCubmMCaEWLnkqj/I+ SzN6NxVj6gsdTpDw9628faWt7QHm0EV4gfmevSHXNa6MW5Jqy03qd0fFQK1s2fPOZgGR OkIp2xhiWRV7xuDABXp3fmxHmE+u2+xlg7lJsD1hCkH504UskftYQN8MOVnUngCfGd4m tZehHLhs3hLOhLEEdQa4enT8gEIGRKkIhySn9gcqtJ70+LJczlj+x9LyabLhJj/RldmT FLvg== MIME-Version: 1.0 In-Reply-To: <5035F7D8.601@shopzeus.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <5035F7D8.601@shopzeus.com> Date: Thu, 23 Aug 2012 19:30:37 +1000 Subject: Re: Guarding arithmetic From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345714240 news.xs4all.nl 6960 [2001:888:2000:d::a6]:53624 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27718 On Thu, Aug 23, 2012 at 7:28 PM, Laszlo Nagy wrote: >> That can work ONLY if the division of 1/0 doesn't raise an exception. >> This is why the concept of NaN exists; I'm not sure if there's a way >> to tell Python to return NaN instead of bombing, but it's most likely >> only possible with floating point, not integer. > > For integers, Python will always raise an exception when you try to divide > by zero. And integers has nothing to do with NaN. Because NaN is meaningful > for floating point numbers only. Python can be compiled to raise floating > point exceptions. (On Python 2, this is a compile time option: FPECTL. On > Python 3, this can be configured runtime: > http://docs.python.org/library/fpectl.html ) Thanks, that's the sort of thing I meant. I'm not familiar enough with Python's floating point handler to know those details. ChrisA