[Python-bugs-list] [ python-Bugs-465527 ] sqrt on a long int returns invalid resul

noreply@sourceforge.net noreply@sourceforge.net
Thu, 27 Sep 2001 13:29:11 -0700


Bugs item #465527, was opened at 2001-09-26 23:54
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=465527&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Edward Kandrot (arcanelord)
Assigned to: Tim Peters (tim_one)
Summary: sqrt on a long int returns invalid resul

Initial Comment:
n = 
1881988129206079638386972394616504398071635633794173827
0076335642298885971523466548531906060650474304531738801
1303396716199692321205734031879550656996221305168759307
650257059L
x = long(math.sqrt(n))

the result of this is that x is off by many orders of 
magnitude.  There should be a sqrt function that 
returns a long integer result so that large integer 
math will work as expected.  I have written this 
function in python, one that would set x to be the 
integer part of a sqrt, but the hd it was on is 
currently damaged.  If this is determined to be an 
actual problem that needs to be fixed, I will submit 
the code in this bug (unless someone beats me to it).

----------------------------------------------------------------------

>Comment By: Edward Kandrot (arcanelord)
Date: 2001-09-27 13:29

Message:
Logged In: YES 
user_id=102159

I am using 2.1.  I saw the problem on Linux previously, but 
I am on a Win2k box now with these results:

>>> x
433818871097844195711080363479661366933416624844037360445918
708654950711556266965073920L
>>> n-x*x
579455590187726959148083548468770884154260745498744050023793
649517960092688750631137087163290051389345006612268597554742
3732078994891141758379026196586090659L

Since I do not have the program to give the correct answer, 
I can not tell you what it is right now (until I fix my 
Linux HD).  I can tell you it is wrong by how much larger 
the remainder is from the sqrt.  n-x*x should be less than
2*x+1, wereas the results from above is 
133570858437146139501587560404236730965976658068588390668591
16036188472L*x+151281127770264061379550826654612638192882839
13990470767939415731499169681374054240419L  (ie many 
magnitudes of order greater than expected).

I will shortly recover the algorithm that calcs sqrt 
correctly and post it here, so at least we can see what I 
was expecting as a result.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-27 10:58

Message:
Logged In: YES 
user_id=6380

Which Python version? On which platform? In 2.1 and 2.2 I
get a decent result.

Assigning to Tim who usually answers these questions.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=465527&group_id=5470