|
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