division by 7 efficiently ???
Paul Rubin
http
Thu Feb 1 15:46:55 EST 2007
"Krypto" <krypto.wizard at gmail.com> writes:
> The correct answer as told to me by a person is
>
> (N>>3) + ((N-7*(N>>3))>>3)
>
>
> The above term always gives division by 7
Well, not exactly:
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(N): return (N>>3) + ((N-7*(N>>3))>>3)
...
>>> f(7)
0
>>> f(70)
9
>>> f(700)
98
More information about the Python-list
mailing list