Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106978
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Accuracy of math.sqrt(), was Re: Serious error in int() function? |
| Date | Thu, 14 Apr 2016 09:46:53 +0200 |
| Organization | None |
| Lines | 62 |
| Message-ID | <mailman.95.1460620029.15650.python-list@python.org> (permalink) |
| References | <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> <570f3e30$0$665$426a74cc@news.free.fr> <nenhtf$1o6$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | news.uni-berlin.de TFyBasz5XhVdAcaOTmNmpgCxdIiiS0T/FY8t/ibqLIBg== |
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'root': 0.04; 'matches': 0.07; 'ast': 0.09; 'integers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'subject:error': 0.11; 'question.': 0.13; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'thread.': 0.16; 'ubuntu.': 0.16; 'wrote:': 0.16; 'integer': 0.18; '>>>': 0.20; 'math': 0.20; 'martin': 0.22; '4.0': 0.22; 'function:': 0.22; 'gcc': 0.22; 'skip:n 60': 0.22; 'seems': 0.23; "python's": 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'linux': 0.26; 'error': 0.27; 'yields': 0.29; 'print': 0.30; 'skip:s 30': 0.31; 'post': 0.31; 'similar': 0.33; 'best,': 0.35; 'false': 0.35; 'question,': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'hi,': 0.38; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'hope': 0.61; 'here.': 0.62; 'subject': 0.70; 'dans': 0.72; 'square': 0.76; 'serious': 0.97 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9d74.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| 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 | <nenhtf$1o6$1@ger.gmane.org> |
| X-Mailman-Original-References | <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> <570f3e30$0$665$426a74cc@news.free.fr> |
| Xref | csiph.com comp.lang.python:106978 |
Show key headers only | View raw
ast wrote: > > <martin.spichty@gmail.com> a écrit dans le message de > news:52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com... >> Hi, >> >> there may be a serious error in python's int() function: >> >> print int(float(2.8/0.1)) >> >> yields >> >> 27 >> >> instead of 28!! >> >> I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu. >> >> Is that known? >> Best, >> Martin > > > I have a similar question, so I post my message here. > Hope this will not annoy the OP Well, you "annoy" me ;) Would you please always take the time to come up with a subject line that matches your question. You should also start a new thread. > Is it sure that the square root of a square number is always > an integer ? > > I would not like to get a result as 345.99999999 > > from math import sqrt > >>>>sqrt(16) > 4.0 >>>> sqrt(16).is_integer() > True > >>>> for n in range(1000000): > ... if not sqrt(n**2).is_integer(): > ... print(sqrt(n**2)) > > it seems to work ... but does it work for all integers ? Even if you get an integer it may not be the one you are expecting: >>> sqrt((10**22)**2) == 10**22 True >>> sqrt((10**23)**2) == 10**23 False >>> sqrt((10**23)**2).is_integer() True >>> int(sqrt((10**23)**2)) 99999999999999991611392
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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