Boost logo

Boost :

Subject: [boost] float_mem_cast
From: Steven Ross (spreadsort_at_[hidden])
Date: 2009-05-26 09:46:33

There is one function necessary for users to be able to cast their own float
types. Should it be in spreadsort.hpp or some separate header file? It
seems silly to have a separate header file for it, but I guess it might be
used on its own.

//Casts a float to the specified integer type
  template<class Data_type, class Cast_type>
  inline Cast_type
  float_mem_cast(const Data_type & data)
    //Only cast IEEE floating-point numbers, and only to a same-sized
    BOOST_STATIC_ASSERT(sizeof(Cast_type) == sizeof(Data_type));
    Cast_type result;
    std::memcpy(&result, &data, sizeof(Cast_type));
    return result;

Boost list run by bdawes at, gregod at, cpdaniel at, john at