Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107018

Re: Serious error in int() function?

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.tal.de!news.wtal.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: Serious error in int() function?
Date Thu, 14 Apr 2016 20:36:12 -0400
Organization IISS Elusive Unicorn
Lines 62
Message-ID <mailman.121.1460680575.15650.python-list@python.org> (permalink)
References <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> <570f3e30$0$665$426a74cc@news.free.fr> <Kr2dnVKiXPpT0JLKnZ2dnUU78TXNnZ2d@brightview.co.uk> <zNSdna8abKekzJLKnZ2dnUU78fHNnZ2d@brightview.co.uk> <3MidnT9boJ97GpLKnZ2dnUU78LPNnZ2d@brightview.co.uk> <rid0hbt5r0pm5pjsjadb23g0f6jib2qrtt@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de CuyGiRiLW9my5JmxEQa0QgoZxK3opJBoPKnj12H9Ki2g==
Return-Path <python-python-list@m.gmane.org>
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; 'root': 0.04; 'bits': 0.07; 'squares': 0.07; 'ast': 0.09; 'bits.': 0.09; 'exp': 0.09; 'integer,': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terminates': 0.09; 'subject:error': 0.11; 'thu,': 0.15; '1e+30': 0.16; '2016': 0.16; '>on': 0.16; 'digits.': 0.16; 'exponent': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'url:home': 0.18; '>>>': 0.20; 'math': 0.20; 'bit': 0.23; 'import': 0.24; 'header:X-Complaints-To:1': 0.26; 'point.': 0.27; 'error': 0.27; 'correct': 0.28; 'function': 0.28; 'decimal': 0.29; 'themselves': 0.29; 'except': 0.34; 'could': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'means': 0.39; 'data': 0.39; 'to:addr:python.org': 0.40; 'more': 0.63; 'between': 0.65; 'square': 0.76; 'dennis': 0.91; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host adsl-108-73-119-88.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <rid0hbt5r0pm5pjsjadb23g0f6jib2qrtt@4ax.com>
X-Mailman-Original-References <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> <570f3e30$0$665$426a74cc@news.free.fr> <Kr2dnVKiXPpT0JLKnZ2dnUU78TXNnZ2d@brightview.co.uk> <zNSdna8abKekzJLKnZ2dnUU78fHNnZ2d@brightview.co.uk> <3MidnT9boJ97GpLKnZ2dnUU78LPNnZ2d@brightview.co.uk>
Xref csiph.com comp.lang.python:107018

Show key headers only | View raw


On Thu, 14 Apr 2016 13:07:03 +0100, blindanagram@nowhere.net declaimed the
following:

>On 14/04/2016 09:13, blindanagram@nowhere.net wrote:
>> On 14/04/2016 08:59, blindanagram@nowhere.net wrote:
>>> On 14/04/2016 07:52, ast wrote:
>> 
>>> This means that the result will be correct provided it has 53 or less
>>> bits - just short of 16 decimal digits (i.e for square numbers with less
>>> than 32 digits).
>>>
>>> With an integer square root function (isqrt), this program:
>>>
>>> for exp in count(20):
>>>   v = 2 ** exp - 1
>>>   if isqrt(v) != sqrt(v):
>>>     print(exp, isqrt(v), sqrt(v))
>>>     break
>>>
>>> terminates with:
>>>
>>>   54 18014398509481983 1.8014398509481982e+16
>>>
>>> showing a first error for a 54 bit square root
>>>
>> I should also have said that the square root of integer squares with
>> between 15 and 30 decimal digits will only be correct if the square
>> numbers themselves are exactly representable in 53 bits.  So we can
>> expect failures for squares with 16 or more digits.
>
>However, if a number with 31 or less digits is known to be the square of
>an integer, the IEEE754 sqrt function will (I believe) give the correct
>result.

	How could it EXCEPT by having ~15 significant digits and an exponent --
since that is all the data that is provided by a double precision floating
point. That is, for example, 

>>> 1000000000000000.0 * 1000000000000000.0
1e+30
>>> import math
>>> math.sqrt(1e30)
1000000000000000.0
>>> 

only has ONE significant digit -- even though it has thirty 0s before the
decimal point.

>>> 100000000000000000.0 * 100000000000000000.0
1e+34
>>> math.sqrt(1e34)
1e+17
>>> 10000000000000000.0 * 10000000000000000.0
1e+32
>>> math.sqrt(1e32)
1e+16
>>> 

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Serious error in int() function? martin.spichty@gmail.com - 2016-04-13 00:41 -0700
  Re: Serious error in int() function? Marko Rauhamaa <marko@pacujo.net> - 2016-04-13 10:55 +0300
  Re: Serious error in int() function? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2016-04-13 10:00 +0200
  Re: Serious error in int() function? Peter Otten <__peter__@web.de> - 2016-04-13 10:03 +0200
  Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-13 09:04 +0100
  Re: Serious error in int() function? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-13 23:51 +1200
  Re: Serious error in int() function? "ast" <nomail@com.invalid> - 2016-04-14 08:52 +0200
    Re: Serious error in int() function? Christian Gollwitzer <auriocus@gmx.de> - 2016-04-14 09:25 +0200
    Accuracy of math.sqrt(), was Re: Serious error in int() function? Peter Otten <__peter__@web.de> - 2016-04-14 09:46 +0200
    Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-14 08:59 +0100
      Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-14 09:13 +0100
        Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-14 13:07 +0100
          Re: Serious error in int() function? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-14 20:36 -0400
            Re: Serious error in int() function? Christian Gollwitzer <auriocus@gmx.de> - 2016-04-15 04:38 +0200
              Re: Serious error in int() function? John Pote <johnhpote@o2.co.uk> - 2016-04-15 12:05 +0100
                Re: Serious error in int() function? alister <alister.ware@ntlworld.com> - 2016-04-15 11:50 +0000
            Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-15 09:41 +0100
              Re: Serious error in int() function? blindanagram@nowhere.net - 2016-04-15 09:41 +0100

csiph-web