Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'that?': 0.05; 'cc:addr :python-list': 0.11; 'compute': 0.16; 'feasible': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'googling': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'skip': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'too': 0.37; 'url:blogspot': 0.65; 'worth': 0.66; 'url:2011': 0.75; 'ideas.': 0.84; 'studying': 0.84; 'subject:base': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=+BVLCbQnnyVVdelks3isD4UwGG1fj1xt2DGjaBeWSLI=; b=VQMAtay4bUREmvZ6V0W3vLGzwSCWY5LA98CpEcIpFv9+bmD2DIc+259eJzIbEXnyZB 40NNx0L1E3/OmLu5Pbj3JJIMMI5VjKmqmjMhj+GY8hCGBQemDi6RMvHzFXln+kOOaWIc fH9p3Aa5licVgd/UM2OcFdtVBboXdEqf45UuEfl+B4+jsf1Zhv3qA2453Mqp49mNVotC SpT10XhhY+kysAIvc2/QuMQbdtvcTmQqbKe7jBdtHzU7BntB4MIlUbHxxbZIzwPFRKiz MlNJ3IPrh0LWf65SfFVlxHeraOTYRe8MTsBGi6lL9lh4CnSeoJ6fcyD0OyJzESEZmCAR WCzw== MIME-Version: 1.0 X-Received: by 10.42.82.6 with SMTP id b6mr6210625icl.51.1407935800559; Wed, 13 Aug 2014 06:16:40 -0700 (PDT) Sender: skip.montanaro@gmail.com In-Reply-To: References: Date: Wed, 13 Aug 2014 08:16:40 -0500 X-Google-Sender-Auth: Vt12wsYATeMQV0CfgjUAI6k9MaM Subject: Re: Log base 2 of large integers From: Skip Montanaro To: Mok-Kong Shen Content-Type: text/plain; charset=UTF-8 Cc: Python 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407935803 news.xs4all.nl 2900 [2001:888:2000:d::a6]:47666 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76194 On Wed, Aug 13, 2014 at 8:05 AM, Mok-Kong Shen wrote: > I like to compute log base 2 of a fairly large integer n but > with math.log(n,2) I got: > > OverflowError: long int too large to convert to float. > > Is there any feasible work-around for that? A bit of googling turned up this page: http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html Might be worth studying for ideas. Skip