Which is faster? ulong or double

Don Clugston dac at nospam.com.au
Thu Sep 27 23:19:43 PDT 2007


Walter Bright wrote:
> Janice Caron wrote:
>> 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.
> 
> Ulong divides are emulated in software only if the divisor has any bits 
> set in the high 32 bits. Otherwise, the DIV instruction is used. There 
> are two DIV's if there are high bits set in the dividend.
> 
> BTW, ulong has more bits of *integral* precision than double or real.

Specifically: on x86, real has 64 bits of signed precision, but only 63 bits 
unsigned.

On most Pentiums, even 32-bit multiplies and divides are slightly slower than 
floating point; but converting integers to floats is slow.
If there are many multiplies, I'd expect fp to be faster.



More information about the Digitalmars-d mailing list