|
Boost : |
Subject: Re: [boost] Proposed templated integer_sort
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-02-02 04:47:19
Steven Ross wrote:
> On Wed, Jan 14, 2009 at 10:26 AM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
>> Phil Endecott wrote:
>>> It would be good if it were possible to automatically detect whether a
>>> floating point type is one for which the cast-to-integer trick works. It
>>> would be great if C++ defined some macro or similar that defined whether
>>> float and double were IEEE 754 or not. (Hmm, is there some sort of
>>> type_traits thing to do this?).
>>
>> Are you thinking of std::numeric_limits<>::is_iec559?
>>
> I've added these static assertions in the casting methods:
> 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);
> That should guarantee I'm casting an IEEE floating-point number to an
> integer of the same size.
I was imagining that you'd use these to enable a specialisation, e.g.
using enable_if, rather than in asserts.
Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk