Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder5.news.weretis.net!feeder1.news.weretis.net!feeder.erje.net!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '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; 'wrote:': 0.15; 'grep': 0.16; 'operators,': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'missed': 0.24; 'object': 0.30; 'from:addr:web.de': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'usual': 0.32; "skip:' 10": 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'there': 0.34; 'addition,': 0.36; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'steven': 0.38; 'think': 0.38; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'methods': 0.40; 'something.': 0.91; 'subject:there': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Is there a way to customise math.sqrt(x) for some x? Date: Sat, 16 Jul 2011 11:37:18 +0200 Organization: None References: <4e214d5a$0$29975$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849f26.dip.t-dialin.net 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310809049 news.xs4all.nl 23907 [2001:888:2000:d::a6]:47097 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9614 Steven D'Aprano wrote: > I have a custom object that customises the usual maths functions and > operators, such as addition, multiplication, math.ceil etc. > > Is there a way to also customise math.sqrt? I don't think there is, but I > may have missed something. There seem to be only three methods that can be customized: $ grep 'LookupSpecial' mathmodule.c method = _PyObject_LookupSpecial(number, "__ceil__", &ceil_str); method = _PyObject_LookupSpecial(number, "__floor__", &floor_str); trunc = _PyObject_LookupSpecial(number, "__trunc__", &trunc_str);