Paolo Carlini <[EMAIL PROTECTED]> writes:

| Michael Veksler wrote:
| 
| >   std::tr1::hash<dobule> is implemented in a very bad way.
| >   it casts double to size_t, which of course does a very poor job on big
| >   values (is the result of 1.0e100 cast to size_t defined ?).
| >  
| >
| A possible solution would be using frexp & co to extract the mantissa
| and then work on it, one way or the other. You can find it proposed
| around. Then, often the exponent is simply discarded.
| 
| What do you think?

It is definitely a good thing to use the full bits of value
representation if we ever want to make all "interesting" bits part of
the hash value.  For reasonable or sane representations it suffices to
get your hand on the object representation, e.g.:

   const int objsize = sizeof (double);
   typedef unsigned char objrep_t[objsize];
   double x = ....;
   objrep_t& p = reintepret_cast<objrep_t&>(x);
   // ...

and let frexp and friends only for less obvious value representation.

-- Gaby

Reply via email to