division by 7 efficiently ???
Nicko
usenet at nicko.org
Fri Feb 2 11:42:07 EST 2007
On Feb 2, 4:21 pm, "Bart Ogryczak" <B.Ogryc... at gmail.com> wrote:
> On Feb 1, 2:00 pm, "Nicko" <use... at nicko.org> wrote:
>
> > precision and the answer that they were looking for was:
> > a = (b * 04444444445L) >> 32
> > Note that the constant there is in octal.
>
> 04444444445L? Shouldn´t it be 04444444444?
> Or more generally,
> const = (1<<bitPrecision)/7
> a = (b * const)>>bitPrecision
It's to do with rounding. What you actually need is
ceiling((1<<bitPrecision)/7), rather than floor((1<<bitPrecision)/7).
Nicko
More information about the Python-list
mailing list