From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-03-15 13:47:16
Paul A Bristow said: (by the date of Wed, 15 Mar 2006 15:23:50 -0000)
> | > | This suggests that it is a broken feature of Microsoft's
> | > | operator>> for doubles read from filestreams.
> | why not just read the string, ans use boost::lexical_cast<double> ?
> | --
> | Janek Kozicki
> I fear that lexical_cast uses the same method of reading from a stringstream
> And that our testing of lexical_cast is insufficient to catch it.
> Some very rough tests of lexical_cast suggest that several percent of not
> very random double values fail to loopback ( 1 bit wrong), but I don't have
> time to work on this at present.
but if during saving lexical_cast<string>(some_double_value) is used
IMHO no data should be lost at all. operator<< for string cannot make a
mistake. Also operator>> for string shouldn't make a mistake, otherwise
copying around textual data with << and >> should lead to data corruption.
(think copying text file using microsoft's operators << and >> )
bear in mind that lexical_cast<string>(foo) converts double to string
without any data loss (that's the exact purpose of lexical_cast). Then
later if this data is treated as string then it's not possible to loss
any information (otherwise we have a plain corruption of textual data).
so during save you convert double to string, then save.
when you load it - you load a string, then convert it to double.
operator>> is not converting anything, it just works with strings.
-- Janek Kozicki |
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk