|
Boost : |
From: John Maddock (john_at_[hidden])
Date: 2008-02-26 09:04:23
John Maddock wrote:
> 1) Floating point classification routines: these are optimised
> implementations of the C99 and C++ TR1 functions fpclassify, isinf,
> isnan, isnormal and isfinite. From Boost-1.35 onwards these are
> already a part of Boost.Math (see
> http://svn.boost.org/svn/boost/trunk/libs/math/doc/sf_and_dist/html/math_toolkit/special/fpclass.html)
> so if accepted the two implementations will get merged.
>
> The review here should focus on the implementation used, and testing
> on whatever platforms you have available - in particular are there any
> circumstances (compiler optimisation settings etc) where this
> implementation breaks?
These look fine to me, and as Johan mentioned, any breakages should be fixed
in endian.hpp.
Sorry to bring this up again (!), but I've been trying to get my head around
the aliasing rules and what is and isn't allowed, in particular by following
the rather useful article here:
http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html
>From this it appears that your current code is perfectly fine, however I
still can't help feeling that we could do better than call an external
function (memcpy) to move 4 or 8 bytes. The suggestion in the article is to
use a union to move from one type to another:
union float_to_int32
{
float f;
boost::uint32_t i;
};
boost::uint32_t get_bits(float f)
{
float_to_int32 u;
u.f = f;
return u.i;
}
I can't claim to have tested exhaustively, but modifying get_bits and
set_bits to use this method seems to work OK for VC8&9 and Minwg GCC.
Thoughts?
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk