Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'function,': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'rewritten': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'lambda': 0.16; 'python-list,': 0.16; 'reedy': 0.16; 'subject:avoiding': 0.16; 'zero,': 0.16; 'math': 0.16; 'posting': 0.18; 'everyone,': 0.19; '(which': 0.21; 'jan': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'division': 0.23; 'function': 0.27; 'hey': 0.29; 'stat': 0.31; 'does': 0.31; 'to:addr:python-list': 0.32; 'example,': 0.33; 'propose': 0.33; 'module': 0.33; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.35; 'too': 0.36; 'useful': 0.37; 'faster': 0.38; 'but': 0.38; 'no.': 0.38; 'received:org': 0.38; 'adds': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'header :Mime-Version:1': 0.39; 'header:Received:5': 0.40; 'as:': 0.64 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Feature suggestion: math.zod for painlessly avoiding ZeroDivisionError Date: Mon, 11 Apr 2011 13:27:28 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 In-Reply-To: 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: 26 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302542864 news.xs4all.nl 81481 [::ffff:82.94.164.166]:41182 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2985 On 4/11/2011 10:10 AM, Natan Yellin wrote: > Hey everyone, > This is my first posting to python-list, so be gentle. > > I propose the following function for the math module (which can, of > course, be rewritten in C): > > zod = lambda a, b: b and a / b This is way too trivial to add. > > zod, the zero or divide function, is useful for division where the > denominator can be 0. For example, here's one line of code > stat = x / y > If y can be zero, that one-liner needs to be rewritten as: > if y != 0: > stat = x / y > else: > stat = 0 No. 'stat = y and x/y', which will be faster than 'stat = zod(x,y)', which does the same thing but adds a function call/ -- Terry Jan Reedy