comp_t
pefv700 at perv.pe.utexas.edu
pefv700 at perv.pe.utexas.edu
Wed May 8 03:03:33 AEST 1991
In article <9105060921.aa11316 at art-sy.detroit.mi.us>, chap at art-sy.detroit.mi.us (j chapman flack) writes...
>mantissa = comp_t & 0x1FFF
>exponent = comp_t & 0xE000
>
>double ticks = ldexp( (double)mantissa, 3*exponent)
>
I would be delighted, actually, to learn that I'm wrong and have
>someone provide a more sensible explanation.
Try
ticks = (double)((comp_t & 0x1fff) << 3 * (comp_t & 0xe000));
The reason your ldexp call is correct is that it is
mantissa times (8 to the power exponent)
or more literally
mantissa times (2 to the power (3 times exponent))
This can be done quicker with a left shift. As K&R2 says,
The value of E1<<E2 is E1 (interpreted as a bit pattern)
left-shifted E2 bits; in the absence of overflow, this
E2
is equivalent to multiplication by 2 .
Chris
More information about the Comp.unix.programmer
mailing list