
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; }

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

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@gmail.com>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

AMDG Steven Ross wrote:
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.
Nevermind what I said. I didn't understand that users would need to call the function. Just leave it in spreadsort.hpp. In Christ, Steven Watanabe

Steven Watanabe skrev:
AMDG
Steven Ross wrote:
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.
Nevermind what I said. I didn't understand that users would need to call the function. Just leave it in spreadsort.hpp.
Isn't this what we need in the bounded_float<> template we reviewed during the constrained value lib? -Thorsten

On Fri, May 29, 2009 at 12:07 AM, Thorsten Ottosen < thorsten.ottosen@dezide.com> wrote:
Isn't this what we need in the bounded_float<> template we reviewed during the constrained value lib?
-Thorsten
If there is another place where it's appropriate to put this typecast, I'd welcome it. I need the cast, but it doesn't have much to do with sorting.

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 26 May 2009 21:26 To: boost@lists.boost.org Subject: Re: [boost] float_mem_cast
AMDG
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
Steven Ross wrote: plus
data sorting); should they use it from the detail namespace? If that's reasonable, then I'll move it.
Nevermind what I said. I didn't understand that users would need to call the function. Just leave it in spreadsort.hpp.
This would indeed seem to quite widely useful - but if you just leave it there, how will anyone find it? It really would be much more useful and discoverable with some docs and tests however minor, even if it stays in spreadsort.hpp? Paul --- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com

Sure, I'll create docs for it. I'm not sure how to test it, besides the tests that already exist for float_sort (which require it to work correctly). I didn't even write the current (functional) implementation of this cast; I'll make sure to attribute it to the author. On Mon, Jun 1, 2009 at 5:29 AM, Paul A. Bristow <pbristow@hetp.u-net.com>wrote:
-----Original Message----- From: boost-bounces@lists.boost.org [mailto: boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 26 May 2009 21:26 To: boost@lists.boost.org Subject: Re: [boost] float_mem_cast
AMDG
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
Steven Ross wrote: plus
data sorting); should they use it from the detail namespace? If that's reasonable, then I'll move it.
Nevermind what I said. I didn't understand that users would need to call the function. Just leave it in spreadsort.hpp.
This would indeed seem to quite widely useful - but if you just leave it there, how will anyone find it?
It really would be much more useful and discoverable with some docs and tests however minor, even if it stays in spreadsort.hpp?
Paul
--- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (4)
-
Paul A. Bristow
-
Steven Ross
-
Steven Watanabe
-
Thorsten Ottosen