[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!

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of n1driver@charter.net Sent: 27 March 2009 17:59 To: boost@lists.boost.org 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
supposed to work? I've tried this on AIX and the test failed at this
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@hetp.u-net.com this is 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/
participants (2)
-
n1driver@charter.net
-
Paul A. Bristow