Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-08-04 09:33:30


 

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of Gennaro Prota
| Sent: 04 August 2006 13:14
| To: boost_at_[hidden]
| Subject: Re: [boost] Spurious warning in lexical_cast.hpp
|
| On Fri, 4 Aug 2006 12:16:03 +0100, "Paul A Bristow"
| <pbristow_at_[hidden]> wrote:
|
| >And in rely to Gennaro's question,
| >
| >| stream.precision(2 + std::numeric_limits<Source>::digits
| * 301/1000);
| >
| >| Does that work for non IEEE 754 floating points too?

| My question was just if it (the formula) requires IEEE754 or not.

IMO, it does NOT require IEEE754 - it only requires
numeric_limits<T>::digits to be correct for that type T.

So, it works for NTL quad_float which is NOT IEEE754.

| As to the docs, this is what I would add. Feedback welcome.
|
| lexical_cast<> offers the following guarantees:
|
| - in the absence of overflow/underflow,
|
| * if a "decimal string" with at most numeric_limits<T>::digits10
| significant digits is converted to a floating type T and back
| to a string the result will equal the original string value.
|
| * if a floating point value having type F is converted to a
| string allowing at least max_digits10 [or our formula here]
| significant decimal digits and back to F the result will
| be the original number.

Well in principle yes, but the C++ Standard is not clear if the second is
REQUIRED,
or is just a Good Quality Implementation.

At present, I only know for certain that MSVC 8.0 (and earlier?) does not
QUITE achieve this - there is a tiny range of double (and of course long
double which are the same) values for which one third of values are one bit
wrong. (For float it is true).

When I reported this as a bug, it was deemed a feature, but I would not be
surprised to see it fixed, since a similar problem existed for float and was
also deemed a fixture, but was fixed at 8.0.

So sadly, it is a desirata not a guarantee :-((

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