answers:
Quote:>... Here a c function that works.
> /* The value is in the low order 13 bits.
> The exponent is in the high order 3 bits.
> It should be possible to use bit fields here.
Using bitfields would be unwise (they change bit order virtually
at random on different machines---often they follow the machine's
native byte order, but there is no such guarantee).
The following is from my new manpage, intended for the next BSDI release.
(This text contains embedded underlines; many newsreaders handle this
correctly.)
The various _ c_ o_ m_ p_ __ t fields are encoded as described above, instead of be-
ing saved in, say, floating point. This gives a large range in a small
space, at a small cost in accuracy. To convert these fields, use the
formula:
u = (v & 0x1fff) << (3 * (v >> 13))
(where v is the _ c_ o_ m_ p_ __ t value and _ u is the time in units of AHZ). The
largest possible value is 8191 * 8^7 or 17,177,772,032 units; since it
takes 64 units to represent a second, this value represents 268,402,688
seconds, or approximately 8.5 years. Note that the numbers remain exact
until the first 8191 units (just under 128 seconds), after which the low
three bits of the value are dropped, so values that represent between 128
and 1023.875 seconds are only accurate to the nearest 8/64 or 1/8th of a
second. Another three bits disappear for each new power of 8, so values
between 1024 and 8191 seconds are only accurate to the second, and so
forth. Further details can be found in Knuth vol 2.
In my copy of Knuth (2nd edition), exercise 6 on page 248 is particularly
relevant.
AHZ differs on different systems; some even use their HZ parameter instead.
--
In-Real-Life: Chris Torek, Berkeley Software Design Inc (+1 510 549 1145)