Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66887 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-11-30 05:05:17


Author: pbristow
Date: 2010-11-30 05:05:14 EST (Tue, 30 Nov 2010)
New Revision: 66887
URL: http://svn.boost.org/trac/boost/changeset/66887

Log:
Check before using max_digits10
Text files modified:
   trunk/libs/math/example/geometric_examples.cpp | 14 ++++++++++----
   trunk/libs/math/example/inverse_chi_squared_example.cpp | 2 --
   trunk/libs/math/example/inverse_gamma_distribution_example.cpp | 13 +++++++++----
   trunk/libs/math/example/inverse_gamma_example.cpp | 12 ++++++++++--
   4 files changed, 29 insertions(+), 12 deletions(-)

Modified: trunk/libs/math/example/geometric_examples.cpp
==============================================================================
--- trunk/libs/math/example/geometric_examples.cpp (original)
+++ trunk/libs/math/example/geometric_examples.cpp 2010-11-30 05:05:14 EST (Tue, 30 Nov 2010)
@@ -156,11 +156,17 @@
 */
     geometric g05(0.5); // Probability of success = 0.5 or 50%
     // Output all potentially significant digits for the type, here double.
-#if (_MSC_VER >= 1600)
- cout.precision(std::numeric_limits<double>::max_digits10);
-#else
- cout.precision(2 + (boost::math::policies::digits<double, boost::math::policies::policy<> >() * 30103UL) / 100000UL);
+
+#ifdef BOOST_NO_NUMERIC_LIMITS_LOWEST
+ int max_digits10 = 2 + (boost::math::policies::digits<double, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
+ cout << "BOOST_NO_NUMERIC_LIMITS_LOWEST is defined" << endl;
+#else
+ int max_digits10 = std::numeric_limits<double>::max_digits10;
 #endif
+ cout << "Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = "
+ << max_digits10 << endl;
+ cout.precision(max_digits10); //
+
     cout << cdf(g05, 0.0001) << endl; // returns 0.5000346561579232, not exact 0.5.
 /*`To get the R discrete behaviour, you simply need to round with,
 for example, the `floor` function.

Modified: trunk/libs/math/example/inverse_chi_squared_example.cpp
==============================================================================
--- trunk/libs/math/example/inverse_chi_squared_example.cpp (original)
+++ trunk/libs/math/example/inverse_chi_squared_example.cpp 2010-11-30 05:05:14 EST (Tue, 30 Nov 2010)
@@ -92,8 +92,6 @@
     << max_digits10 << endl;
   cout.precision(max_digits10); //
 
- cout << _MSC_VER << ' ' << _MSC_FULL_VER << ' ' << _CPPLIB_VER << endl;
-
   inverse_chi_squared ichsqdef; // All defaults - not very useful!
   cout << "default df = " << ichsqdef.degrees_of_freedom()
     << ", default scale = " << ichsqdef.scale() << endl; // default df = 1, default scale = 0.5

Modified: trunk/libs/math/example/inverse_gamma_distribution_example.cpp
==============================================================================
--- trunk/libs/math/example/inverse_gamma_distribution_example.cpp (original)
+++ trunk/libs/math/example/inverse_gamma_distribution_example.cpp 2010-11-30 05:05:14 EST (Tue, 30 Nov 2010)
@@ -32,10 +32,15 @@
   cout << "Example using Inverse Gamma distribution. " << endl;
   // TODO - awaiting a real example using Bayesian statistics.
 
- cout.precision(std::numeric_limits<double>::max_digits10); //
-
- int i = std::numeric_limits<double>::max_digits10;
- cout << "std::numeric_limits<double>::max_digits10 = " << i << endl;
+#ifdef BOOST_NO_NUMERIC_LIMITS_LOWEST
+ int max_digits10 = 2 + (boost::math::policies::digits<double, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
+ cout << "BOOST_NO_NUMERIC_LIMITS_LOWEST is defined" << endl;
+#else
+ int max_digits10 = std::numeric_limits<double>::max_digits10;
+#endif
+ cout << "Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = "
+ << max_digits10 << endl;
+ cout.precision(max_digits10); //
 
   double shape = 1.;
   double scale = 1.;

Modified: trunk/libs/math/example/inverse_gamma_example.cpp
==============================================================================
--- trunk/libs/math/example/inverse_gamma_example.cpp (original)
+++ trunk/libs/math/example/inverse_gamma_example.cpp 2010-11-30 05:05:14 EST (Tue, 30 Nov 2010)
@@ -28,8 +28,16 @@
 {
   cout << "Example 1 using Inverse Gamma function. " << endl;
 
- cout.precision(std::numeric_limits<double>::max_digits10);
-
+ #ifdef BOOST_NO_NUMERIC_LIMITS_LOWEST
+ int max_digits10 = 2 + (boost::math::policies::digits<double, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
+ cout << "BOOST_NO_NUMERIC_LIMITS_LOWEST is defined" << endl;
+#else
+ int max_digits10 = std::numeric_limits<double>::max_digits10;
+#endif
+ cout << "Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = "
+ << max_digits10 << endl;
+ cout.precision(max_digits10); //
+
   double x = 1.;
   double a = 10;
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk