// (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()
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
}
}
- catch(std::exception ex)
+ catch(const std::exception& ex)
{
std::cout << "Caught Exception " << ex.what() << std::endl;
}
*/
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
}
{
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