From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-08-03 09:17:56
On Thu, 3 Aug 2006 12:29:34 +0100, "Paul A Bristow"
>| >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 \
>| ] /**/
This was important; see below.
>This seems overcomplicated to me.
Uh? Ok, I started with the idea to not use numeric_limits<>, then used
it :-) But I typed directly in the newsreader window so I'm forgiven
(by myself :-P)
>the guaranteed 'minimum' digits are already defined by
>numeric_limits<>::digits10() (for float 6)
>and the next version of C++ will provide numeric_limits<>::max_digits10()
>(for float 9)
I know. One point I'm not sure about, though: is it the intent for it
to be defined (and != 0) for non IEEE 754 implementations too?
>so all we need to do is to use the
>stream.precision(2 + std::numeric_limits<Source>::digits * 301/1000);
Does that work for non IEEE 754 floating points too? I guess not. And
in that case we have to check.
There were two other points addresses by my code: single templates (or
metafunctions) are largely preferable to the single monolithic
numeric_limits (especially in boost, where including "boost/limits"
will likely bring the world into your translation unit). That's, I
guess, the position of most boosters. Secondly, static const data
members of integral types (see also core issue 454) easily lead to ODR
violations, with no diagnostic required. I'm eagerly waiting for
strongly typed enums to solve that problem. The issue is: you can
inadvertently bind the expression to a reference, for instance by
using a vector<>::push_back, and nobody will provide a definition for
you. Enums do not have such lvalue complications. I'd like that the
declaration of static const ints members be made a definition (I
believe modern linkers can manage that) but who knows... will that
ever happen? (Probably obvious answer here)
-- [ 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