Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-08-02 17:10:18


On Wed, 2 Aug 2006 20:35:19 +0100, "Paul A Bristow"
<pbristow_at_[hidden]> wrote:
  
>| But...: are you serializing floating point values by means of
>| lexical_cast?
>
>No - I meant 'stringizing'

Ok. It seems to me we need something along these lines (off the top of
my head):

#include "boost/limits.hpp"

#define BOOST_is_ieee754(t) \
    typedef char required [ \
        std::numeric_limits<t>::is_iec559? 1 : -1 \
    ] /**/

template <typename T>
struct digits2
{
    enum { value =
        std::numeric_limits<T>::digits };
};

template <typename T>
struct min_digits_10
{
    BOOST_is_ieee754(T);

    enum { value =
        30103 * (digits2<T>::value - 1) / 100000 };
};

template <typename T>
struct max_digits_10
{
    BOOST_is_ieee754(T);

    enum { value = 2 +
        30103 * digits2<T>::value / 100000
    };
}

#undef BOOST_is_ieee754

--
[ Gennaro Prota, C++ developer for hire ]

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