Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-11-09 12:49:26


 

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of Gennadiy Rozental
| Sent: 08 November 2006 18:48
| To: boost_at_[hidden]
| Subject: Re: [boost] Boost.Test feature request
|
|
| "John Maddock" <john_at_[hidden]> wrote in message
| news:000701c70357$ae886180$c9541b56_at_fuji...
| >I have a couple of annoying issues with Boost.Test's output
| on failed >tests:

| > 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.

At present, with a UDT one can get a message that, in effect, says

"difference between a{2} and a{2} exceeds 0"

It can be avoided by adding

ostr.precision(std::numeric_limits<long double>::digits10 + 2);

to get

"difference between {2} and {2.0000000000000009} exceeds 0"

although I would personally actually prefer for all the trailing zeros to be shown too thus, explicitly showing the precision of all
values:

"difference between a{2.0000000000000000} and b{2.0000000000000009} exceeds 0"

but this may not be everyones taste, so perhaps it can be optional?

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).

HTH

Paul

---
Paul A Bristow
Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB
+44 1539561830 & SMS, Mobile +44 7714 330204 & SMS
pbristow_at_[hidden]
 

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