Boost logo

Boost :

Subject: Re: [boost] float_mem_cast
From: Steven Ross (spreadsort_at_[hidden])
Date: 2009-05-26 12:56:41


My samples use the typecast because it's necessary when sorting on a
floating point key that isn't identical to the data type (such as key plus
data sorting); should they use it from the detail namespace? If that's
reasonable, then I'll move it.

On Tue, May 26, 2009 at 6:53 AM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> AMDG
>
>
> Steven Ross wrote:
>
>> 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
>> integer
>> BOOST_STATIC_ASSERT(sizeof(Cast_type) == sizeof(Data_type));
>> BOOST_STATIC_ASSERT(std::numeric_limits<Data_type>::is_iec559);
>> BOOST_STATIC_ASSERT(std::numeric_limits<Cast_type>::is_integer);
>> Cast_type result;
>> std::memcpy(&result, &data, sizeof(Cast_type));
>> return result;
>> }
>>
>>
>
> Pu it in a detail namespace. If others need the same functionality,
> we can discuss generalizing it then.
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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