Which is faster? ulong or double
Robert Fraser
fraserofthenight at gmail.com
Wed Oct 3 15:37:56 PDT 2007
Chris Miller Wrote:
> On Thu, 27 Sep 2007 15:14:04 -0400, Janice Caron <caron800 at googlemail.com>
> wrote:
>
> > I have this app I've written, and it needs to keep track of an integer
> > quantity (time in microseconds, as it happens, but that's an
> > unimportant detail). The point is, there are circumstances where the
> > numbers involved get bigger than uint.max.
> >
> > So the question is, given that I'm using a 32-bit platform, should I
> > switch to ulong, or to double?
> >
> > ulong sounds the most logical, since the quantity will always be an
> > integer, but (correct me if I'm wrong) ulongs are emulated in
> > software, which is fine for add and subtract, but not so fine for
> > divide; whereas doubles have direct hardware support, and so might
> > actually end up being faster if there are lots of divides.
> >
> > Am I talking nonsense? Is there a recommendation?
>
> I just came across this:
> http://lua-users.org/wiki/FloatingPoint
I would *hope* that the compiler would be able to optimize this if it could prove that a double-precision floating point would have the same semantics as a long integer... but I guess with stuff like inline ASM plus the fact that doubles don't have the same width as ulong, this is a pipe dream.
More information about the Digitalmars-d
mailing list