Paul Eggert said:
Thanks for the tour of some of the darker corners of C; I didn't realize all the ins and outs of hosts with padding bits.
You're welcome.
/* ** Algorithm courtesy Paul Eggert (eggert@cs.ucla.edu).
No credit?
#ifndef HAVE_STDINT_H #define HAVE_STDINT_H (199901 <= __STDC_VERSION__)
19910L (can you say "16 bits"?)
#if HAVE_STDINT_H #include <stdint.h> #define uintmax uintmax_t
I always feel typedef is safer for this sort of thing.
/* ** Use floating point if there should be no double-rounding error. ** However, avoid long double if it must be wider than needed, ** as it's sometimes much more expensive in these cases ** (e.g., 64-bit sparc). */ if (TYPE_BIT(time_t) <= DBL_MANT_DIG || (TYPE_FLOATING(time_t) && sizeof(time_t) < sizeof(long_double))) {
Using != allows for certain perverse implementations. Not important, though.
if ((TYPE_BIT(time_t) <= LDBL_MANT_DIG && (TYPE_BIT(time_t) == LDBL_MANT_DIG || (TYPE_SIGNED(time_t) && UINTMAX_MAX / 2 < INTMAX_MAX)))
Why write this last test like this? UINTMAX_MAX and INTMAX_MAX are both going to be numbers of the form 2**N-1. Furthermore, UINTMAX_MAX >= INTMAX_MAX. So that last one can be done as UINTMAX_MAX == INTMAX_MAX. It happens again later. -- Clive D.W. Feather | Work: <clive@demon.net> | Tel: +44 20 8495 6138 Internet Expert | Home: <clive@davros.org> | Fax: +44 870 051 9937 Demon Internet | WWW: http://www.davros.org | Mobile: +44 7973 377646 Thus plc | |