Boost logo

Boost :

From: Teemu Torma (teemu_at_[hidden])
Date: 2008-04-18 17:45:00


On Friday 18 April 2008, Giovanni Piero Deretta wrote:
>      inline std::size_t float_hash_impl(float v)
>      {
>             std::size_t seed;
>             std::memcpy(&x, &v, sizeof(x));
>             return seed;
>      }
>
> should work and should produce optimal code, at least with a recent
> gcc.

Wouldn't casting using union be safe and efficient in all cases?
Something like:

       inline std::size_t float_hash_impl(float v)
       {
              union { float v; std::size_t seed; } u;
              u.v = v;
              return u.seed;
       }

Teemu


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk