]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/multiprecision/example/numeric_limits_snips.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / multiprecision / example / numeric_limits_snips.cpp
index e114f0a2715ac7895d318d45c3a059f306591eb8..50baf92bda273d7895e704c14b3629042c77dd97 100644 (file)
@@ -7,17 +7,10 @@
 // (See accompanying file LICENSE_1_0.txt
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-// Examples of numeric_limits usage as snippets for multiprecision documentation.
+// Examples of std::numeric_limits usage as snippets for multiprecision documentation at multiprecision.qbk.
 
 // Includes text as Quickbook comments.
 
-#include <iostream>
-#include <iomanip>
-#include <string>
-#include <sstream>
-#include <limits> // numeric_limits
-#include <iomanip>
-#include <locale>
 #include <boost/assert.hpp>
 
 #include <boost/math/constants/constants.hpp>
 #include <boost/test/unit_test.hpp> // Boost.Test
 #include <boost/test/floating_point_comparison.hpp>
 
-static long double const log10Two = 0.30102999566398119521373889472449L; // log10(2.)
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <sstream>
+#include <limits> // numeric_limits
+#include <iomanip>
+#include <locale>
+
+// static long double const log10Two = 0.30102999566398119521373889472449L; // log10(2.)
+// It is more portable useful to use a Boost macro
+// See https://www.boost.org/doc/libs/release/libs/config/doc/html/boost_config/boost_macro_reference.html
+BOOST_STATIC_CONSTEXPR long double log10Two = 0.30102999566398119521373889472449L; 
+// which expands to static constexpr on standard C++11 and up, but static const on earlier versions.
+
+  /*`By default, output would only show the standard 6 decimal digits,
+ so set precision to show all 50 significant digits, including any trailing zeros.
+ This is generally useful to show the implicit precision of the type of the value.
+*/
+
+
+
 
 template <typename T>
 int max_digits10()
@@ -66,10 +79,14 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
     std::cout.precision(max_digits10<T>());
 #else
   #if(_MSC_VER <= 1600)
-   //  Wrong value for std::numeric_limits<float>::max_digits10.
+   //  The MSVC 2010 version had the wrong value for std::numeric_limits<float>::max_digits10.
     std::cout.precision(max_digits10<T>());
   #else // Use the C++11 max_digits10.
      std::cout.precision(std::numeric_limits<T>::max_digits10);
+     std::cout.precision(std::numeric_limits<T>::digits10);
+     std::cout.setf(std::ios_base::showpoint); // Append any trailing zeros,
+     // or more memorably
+     std::cout << std::showpoint << std::endl; // 
   #endif
 #endif
 
@@ -146,7 +163,7 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
   }
 
   }
-  catch(std::exception ex)
+  catch(const std::exception& ex)
   {
     std::cout << "Caught Exception " << ex.what() << std::endl;
   }
@@ -260,13 +277,15 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
 */
     RealType tolerance = boost::math::tools::epsilon<RealType>() * 2;
 //] [epsilon_4]
+    (void)tolerance; // warning suppression
   }
 
   {
+    bool b = 
 //[digits10_5
     -(std::numeric_limits<double>::max)() == std::numeric_limits<double>::lowest();
 //] [/digits10_5]
-//  warning C4553: '==': result of expression not used; did you intend '='? is spurious.
+    (void)b;  // warning suppression
   }
 
   {
@@ -379,8 +398,6 @@ so the default expression template parameter has been replaced by `et_off`.]
 
   if (std::numeric_limits<cpp_bin_float_quad>::has_quiet_NaN == true)
   {
-    cpp_bin_float_quad tolerance =  3 * std::numeric_limits<cpp_bin_float_quad>::epsilon();
-
     cpp_bin_float_quad NaN =  std::numeric_limits<cpp_bin_float_quad>::quiet_NaN();
     std::cout << "cpp_bin_float_quad NaN is "  << NaN << std::endl; //   cpp_bin_float_quad NaN is nan