
To access the native binary representation of floating-point type T, isn't it easier & safer to use a union of T and a character array with sizeof (T) elements? Matt Pfligersdorffer, Christian wrote:
Hello all,
we use fp_utilities in our portable binary archive implementation to serialize floating point numbers. For doing so we found the functions fp_traits<T>_impl::get_bits() and set_bits() to be exactly what we need. In combination with Beman Dawes endian library we're able to transfer binary data between ppc-32 and x86-32 reliably. This might serve as a usecase since John Maddock pointed out serialization as a prominent application of the library.
/** * save floating point types * * We simply rely on fp_traits to extract the bit pattern into an (unsigned) * integral type and store that into the stream. * * \todo treat nan values using fp_classify */ template <typename T> BOOST_DEDUCED_TYPENAME boost::enable_if<boost::is_floating_point<T>
::type
save(const T & t, dummy<3> = 0) { using namespace boost::math::detail; BOOST_DEDUCED_TYPENAME fp_traits<T>::type::bits bits; fp_traits<T>::type::get_bits(t, bits); save(bits); }
As you can see our code depends on functions that apparently are not part of the public interface and I wonder why. Perhaps I overlooked something? Those interested in the full code can find it in the boost vault.
To sum it up: We think the fp_utilities provide useful functionality and our tests indicate reliability that can be counted on. So thank you Johan Rade for this contribution!
Best Regards,
-- Christian Pfligersdorffer Software Engineering http://www.eos.info
John Maddock wrote:
The review of Johan Rade's floating point utilities starts today.
[...]
3) C++ locale facets: these will read and write non-finite numbers in a portable and round-trippable way: that is not otherwise possible with current C++ std library implementations. These are particularly useful for number-serialisation for example.
Since the design is already specified by the C++ standard for these facets, your review here should focus on implementation, testing, documentation, and perhaps where in Boost these should best be placed if accepted.
These look to be a useful collection of utilities, so I'll look forward to your reviews,
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users