Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2006-11-09 15:42:02


"Paul A Bristow" <pbristow_at_[hidden]> wrote in message
news:E1GiE1n-000204-61_at_he304war.uk.vianw.net...
> | > 2) If the type has no numeric_limits support, say if it's
> | a composite
> | > type,
> | > like std::complex<double> then you don't get enough digits
> | to tell what
> | > the
> | > problem is. Could the code default to whatever digits
> | long-double has?
> | > Again a minor change to print_log_value (in my experience
> | std lib's ignore
> | > requests for more digits than a type really has anyway, so
> | it should be
> | > harmless?).
> |
> | Could you provide the code?
>
> I've been investigating and experimenting with this a bit.
...

> So I've got as far as changing set_precision to:
>
> void set_precision( std::ostream& ostr, mpl::false_ )
> {
> ostr.setf(std::ios::showpoint); // Show all significant trailing zeros.
> if(std::numeric_limits<T>::is_specialized &&
> std::numeric_limits<T>::radix == 10)
> { // All decimal types, perhaps including NTL::RR where digits10 ==
> runtime set precision.
> ostr.precision(std::numeric_limits<T>::digits10);
> }
> else if (std::numeric_limits<T>::digits == 0)
> { // User-defined type for which digits (significand bits) value has not
> been assigned,
> // even if is_specialized == true, perhaps assigning other
> numeric_limits values.
> ostr.precision(std::numeric_limits<long double>::digits10 + 2);
> // But this may still not be enough to avoid misleading error messages
> // caused by not enough decimal digits being displayed.
> // User-defined types shuld define digits, even if approximately, as a
> workaround.
> }
> else if( std::numeric_limits<T>::is_specialized &&
> std::numeric_limits<T>::radix == 2 )
> { // && std::numeric_limits<T>::digits != 0)
> ostr.precision( 2 + std::numeric_limits<T>::digits * 301/1000 );
> // std::numeric_limits<T>::max_digits10; for C++0x
> }
> // else default is equivalent to ostr.precision(6);
> } // void set_precision
>
> And this seems to work as I suggest it should.
>
> But the logic of this is more complicated than might appear, so other
> views are welcome.
>
> (Also what are views on the usefulness of trailing zeros to show the
> implicit range? It is certainly helpful for in testing
> precision of floating-point functions).

We will have to return to this a bit later. Also I would like to hear from
you the rationale for all the conditions and selected precisions. And I
would also like to hear more opinions on this.

Gennadiy


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