|
Boost : |
Subject: Re: [boost] [Random] Question on random_test.cpp
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-03-27 14:47:43
This is known from lexical cast loopback test - see
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac
kID=98770 (requires sign-in)
For my money, this is a 'buglet' in the istream library - but MS say it is a
feature.
There is no language guarantee, but my tests showed that it did work only if
you use enough decimal digits (17) for 64 bit doubles. << setprecision(17)
AND for MSVC you need to use << scientific format.
I am told that GCC library is OK.
Paul
--- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow_at_[hidden] > -----Original Message----- > From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On > Behalf Of n1driver_at_[hidden] > Sent: 27 March 2009 17:59 > To: boost_at_[hidden] > Subject: [boost] [Boost][Random] Question on random_test.cpp > > The following is an excerpt from the random_test.cpp file (part of the > instantiate_urng function): > > urng2 = urng; > > { > // narrow stream first > std::ostringstream file; > file << urng; > // move forward > urng(); > // restore old state > std::istringstream input(file.str()); > input >> urng; > // std::cout << file.str() << std::endl; > #if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // MSVC brokenness > // advance some more so that state is exercised > for(int i = 0; i < 10000; ++i) { > urng(); > urng2(); > } > BOOST_CHECK(urng == urng2); > #endif // BOOST_MSVC > } > > My concern is that when a random number generator with an underlying double type > (like fibonacci607) is stored to the stream and then pulled back out, then > precision may be lost, and the underlying data is not guaranteed to be the same. > If a double is written out to a stream in decimal form and then read back in the > value may be changed. Am I missing some sort of language guarantee that this is > supposed to work? I've tried this on AIX and the test failed at this point for > fibonacci607 because some (but not all) of the underlying doubles had changed > after the object was stored and retrieved. > > Thanks! > _______________________________________________ > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost > > > > > > E-mail message checked by Spyware Doctor (6.0.0.386) > Database version: 5.12060 > http://www.pctools.com/uk/spyware-doctor-antivirus/ E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.12060 http://www.pctools.com/uk/spyware-doctor-antivirus/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk