Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

I have also some ideas about algorithmic optimizations (they need to be 
tested). In classic formula $a_{i+1} = a_i + (n - a_i^2)/(2*a_i)$ we can 
calculate $n - a_i^2$ as $(n - a_{i-1}^2) - (a_i^2 - a_{i-1})^2 = (n - 
a_{i-1}^2) - (a_i^2 - a_{i-1})*(a_i^2 + a_{i-1})$. $n - a_i^2$ usually is much 
smaller than $n$, so this can speed up subtraction and division. Things become 
more complicated when use shifts as in your formula, but I think that we can 
get benefit even in this case. This can also speed up the final check $a_i^2 <= 
n$.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36957>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to