Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106929
| Path | csiph.com!feeder.erje.net!2.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!local2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Wed, 13 Apr 2016 03:04:24 -0500 |
| Subject | Re: Serious error in int() function? |
| To | martin.spichty@gmail.com |
| References | <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> |
| Newsgroups | comp.lang.python |
| From | blindanagram@nowhere.net |
| Message-ID | <570DFD89.7010808@nowhere.net> (permalink) |
| Date | Wed, 13 Apr 2016 09:04:25 +0100 |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 |
| MIME-Version | 1.0 |
| In-Reply-To | <52f7516c-8601-4252-ab16-bc30c59c8306@googlegroups.com> |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Lines | 23 |
| X-Usenet-Provider | http://www.giganews.com |
| X-Trace | sv3-TH4fb2Tu5AviG4wAToPrBgDkkr2/CSuh5Cvdh1Kg5kH9Ui/ggdc24dVWYSGMv1MbwUCHUexhFfg+Y+m!gJuOscASRsBUw73UIsqNlaHolw1oPmxoDUqu/RZcmD911Yq885DgXjv2wrL3R62luRGgt3w1VA== |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 1689 |
| Xref | csiph.com comp.lang.python:106929 |
Show key headers only | View raw
On 13/04/2016 08:41, martin.spichty@gmail.com wrote: > 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? This arises because finite floating point arithmetic is not exact so 2.8/0.1 results in 27.999999999999996. And, since the int() function truncates towards zero, this results in a value of 27. If you want the nearest integer you should use round(x) rather than int(x).
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