Re: Serious error in int() function?

2016-04-15 Thread alister
On Fri, 15 Apr 2016 12:05:18 +0100, John Pote wrote: > On 15/04/2016 03:38, Christian Gollwitzer wrote: >> Am 15.04.16 um 02:36 schrieb Dennis Lee Bieber: > 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 s

Re: Serious error in int() function?

2016-04-15 Thread John Pote
On 15/04/2016 03:38, Christian Gollwitzer wrote: Am 15.04.16 um 02:36 schrieb Dennis Lee Bieber: 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

Re: Serious error in int() function?

2016-04-15 Thread blindanagram
On 15/04/2016 01:36, Dennis Lee Bieber wrote: > On Thu, 14 Apr 2016 13:07:03 +0100, blindanag...@nowhere.net declaimed the > following: > >> On 14/04/2016 09:13, blindanag...@nowhere.net wrote: >>> On 14/04/2016 08:59, blindanag...@nowhere.net wrote: On 14/04/2016 07:52, ast wrote: >>> T

Re: Serious error in int() function?

2016-04-14 Thread Christian Gollwitzer
Am 15.04.16 um 02:36 schrieb Dennis Lee Bieber: 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

Re: Serious error in int() function?

2016-04-14 Thread blindanagram
On 14/04/2016 09:13, blindanag...@nowhere.net wrote: > On 14/04/2016 08:59, blindanag...@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 >> t

Re: Serious error in int() function?

2016-04-14 Thread blindanagram
On 14/04/2016 08:59, blindanag...@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 (is

Re: Serious error in int() function?

2016-04-14 Thread blindanagram
On 14/04/2016 07:52, ast wrote: > > a écrit dans le message de > news:52f7516c-8601-4252-ab16-bc30c59c8...@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

Accuracy of math.sqrt(), was Re: Serious error in int() function?

2016-04-14 Thread Peter Otten
ast wrote: > > a écrit dans le message de > news:52f7516c-8601-4252-ab16-bc30c59c8...@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.

Re: Serious error in int() function?

2016-04-14 Thread Christian Gollwitzer
Am 14.04.16 um 08:52 schrieb ast: Is it sure that the square root of a square number is always an integer ? Mathematically, yes. I would not like to get a result as 345. from math import sqrt sqrt(16) 4.0 sqrt(16).is_integer() True for n in range(100): ... if not

Re: Serious error in int() function?

2016-04-13 Thread ast
a écrit dans le message de news:52f7516c-8601-4252-ab16-bc30c59c8...@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, Marti

Re: Serious error in int() function?

2016-04-13 Thread Gregory Ewing
martin.spic...@gmail.com wrote: print int(float(2.8/0.1)) yields 27 instead of 28!! This is a consequence of the fact that the machine does floating point arithmetic in binary, not decimal. 0.1 is not exactly representable as a binary floating point number, and the result of the division co

Re: Serious error in int() function?

2016-04-13 Thread blindanagram
On 13/04/2016 08:41, martin.spic...@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 f

Re: Serious error in int() function?

2016-04-13 Thread Alain Ketterlin
martin.spic...@gmail.com writes: > print int(float(2.8/0.1)) > > yields > > 27 > > instead of 28!! That's how floating-point arithmetic works: look at the result of 2.8/0.1 to see why int() is correct. > Is that known? Yes, it is known, and correct since you use "float". See http://floating-poi

Re: Serious error in int() function?

2016-04-13 Thread Peter Otten
martin.spic...@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? Yes. C has the same error as has every ot

Re: Serious error in int() function?

2016-04-13 Thread Marko Rauhamaa
martin.spic...@gmail.com: > there may be a serious error in python's int() function: > > print int(float(2.8/0.1)) > > yields > > 27 > > instead of 28!! It is not an error but a normal artifact of decimal-to-binary conversion. Marko -- https://mail.python.org/mailman/listinfo/python-list

Serious error in int() function?

2016-04-13 Thread martin . spichty
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 -- https://mail.python.org/mailman/listinfo/python-list