Re: >> to accelerate division

From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 12/08/04


Date: Wed, 08 Dec 2004 10:30:58 GMT

David Kastrup <dak@gnu.org> wrote:

> Ben Pfaff <blp@cs.stanford.edu> writes:
>
> > You can implement i/3 as a multiplication followed by a bit
> > shift. In some cases this may be an improvement. However, if it
> > is an improvement, your compiler may already be doing it for you.
>
> Why not just write
>
> i *= 2863311531;
>
> As long as i is multiple of 3, this will work fine on 32bit machines.

Not if i is a signed int, it won't - at least, it's not guaranteed to.
Signed overflow has undefined behaviour.

Richard



Relevant Pages

  • Re: >> to accelerate division
    ... David Kastrup wrote: ... >> shift. ... your compiler may already be doing it for you. ... Not if i is a signed int, it won't - at least, it's not guaranteed to. ...
    (comp.lang.c)
  • Re: >> to accelerate division
    ... David Kastrup wrote: ... >> shift. ... your compiler may already be doing it for you. ... Not if i is a signed int, it won't - at least, it's not guaranteed to. ...
    (comp.programming)
  • Re: >> to accelerate division
    ... David Kastrup writes: ... >> shift. ... your compiler may already be doing it for you. ... much better choice to get a compiler with a smart optimizer. ...
    (comp.programming)
  • Re: >> to accelerate division
    ... David Kastrup writes: ... >> shift. ... your compiler may already be doing it for you. ... much better choice to get a compiler with a smart optimizer. ...
    (sci.math)
  • Re: >> to accelerate division
    ... David Kastrup writes: ... >> shift. ... your compiler may already be doing it for you. ... much better choice to get a compiler with a smart optimizer. ...
    (comp.lang.c)