From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- .../html/math_toolkit/high_precision/e_float.html | 68 ++++ .../html/math_toolkit/high_precision/float128.html | 65 ++++ .../html/math_toolkit/high_precision/use_mpfr.html | 117 +++++++ .../high_precision/use_multiprecision.html | 364 +++++++++++++++++++++ .../html/math_toolkit/high_precision/use_ntl.html | 74 +++++ .../math_toolkit/high_precision/using_test.html | 144 ++++++++ .../high_precision/why_high_precision.html | 139 ++++++++ 7 files changed, 971 insertions(+) create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/e_float.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/float128.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/use_mpfr.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/use_multiprecision.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/use_ntl.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/using_test.html create mode 100644 boost/libs/math/doc/html/math_toolkit/high_precision/why_high_precision.html (limited to 'boost/libs/math/doc/html/math_toolkit/high_precision') diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/e_float.html b/boost/libs/math/doc/html/math_toolkit/high_precision/e_float.html new file mode 100644 index 00000000..2853c20c --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/e_float.html @@ -0,0 +1,68 @@ + + + +Using e_float Library + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Boost.Multiprecision + was a development from the e_float + (TOMS Algorithm 910) library by Christopher Kormanyos. +

+

+ e_float can still be used with Boost.Math library via the header: +

+
<boost/math/bindings/e_float.hpp>
+
+

+ And the type boost::math::ef::e_float: + this type is a thin wrapper class around ::e_float which provides the necessary + syntactic sugar to make everything "just work". +

+

+ There is also a concept checking test program for e_float support here. +

+

+ New projects are recommended to use Boost.Multiprecision + with cpp_float backend instead. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/float128.html b/boost/libs/math/doc/html/math_toolkit/high_precision/float128.html new file mode 100644 index 00000000..1c3dbf0b --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/float128.html @@ -0,0 +1,65 @@ + + + +Using with GCC's __float128 datatype + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ At present support for GCC's native __float128 + datatype is extremely limited: the numeric constants will all work with that + type, and that's about it. If you want to use the distributions or special + functions then you will need to provide your own wrapper header that: +

+
    +
  • + Provides std::numeric_limits<__float128> support. +
  • +
  • + Provides overloads of the standard library math function for type __float128and which forward to the + libquadmath equivalents. +
  • +
+

+ Ultimately these facilities should be provided by GCC and libstdc++. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/use_mpfr.html b/boost/libs/math/doc/html/math_toolkit/high_precision/use_mpfr.html new file mode 100644 index 00000000..a8482be3 --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/use_mpfr.html @@ -0,0 +1,117 @@ + + + +Using With MPFR or GMP - High-Precision Floating-Point Library + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The special functions and tools in this library can be used with MPFR + (an arbitrary precision number type based on the GNU + Multiple Precision Arithmetic Library), either via the bindings in + boost/math/bindings/mpfr.hpp, + or via boost/math/bindings/mpreal.hpp. +

+

+ New projects are recommended to use Boost.Multiprecision + with GMP/MPFR backend instead. +

+

+ In order to use these bindings you will need to have installed MPFR + plus its dependency the GMP library. + You will also need one of the two supported C++ wrappers for MPFR: gmpfrxx (or mpfr_class), + or mpfr-C++ (mpreal). +

+

+ Unfortunately neither mpfr_class + nor mpreal quite satisfy + our conceptual requirements, so there is a very thin set of additional interfaces + and some helper traits defined in boost/math/bindings/mpfr.hpp + and boost/math/bindings/mpreal.hpp + that you should use in place of including 'gmpfrxx.h' or 'mpreal.h' directly. + The classes mpfr_class or + mpreal are then usable unchanged + once this header is included, so for example mpfr_class's + performance-enhancing expression templates are preserved and fully supported + by this library: +

+
#include <boost/math/bindings/mpfr.hpp>
+#include <boost/math/special_functions/gamma.hpp>
+
+int main()
+{
+   mpfr_class::set_dprec(500); // 500 bit precision
+   //
+   // Note that the argument to tgamma is
+   // an expression template - that's just fine here.
+   //
+   mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2)));
+   std::cout << std::setprecision(50) << v << std::endl;
+}
+
+

+ Alternatively use with mpreal + would look like: +

+
#include <boost/math/bindings/mpreal.hpp>
+#include <boost/math/special_functions/gamma.hpp>
+
+int main()
+{
+   mpfr::mpreal::set_precision(500); // 500 bit precision
+   mpfr::mpreal v = boost::math::tgamma(sqrt(mpfr::mpreal(2)));
+   std::cout << std::setprecision(50) << v << std::endl;
+}
+
+

+ For those functions that are based upon the Lanczos + approximation, the bindings defines a series of approximations with + up to 61 terms and accuracy up to approximately 3e-113. This therefore sets + the upper limit for accuracy to the majority of functions defined this library + when used with either mpfr_class + or mpreal. +

+

+ There is a concept checking test program for mpfr support here + and here. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/use_multiprecision.html b/boost/libs/math/doc/html/math_toolkit/high_precision/use_multiprecision.html new file mode 100644 index 00000000..db2192df --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/use_multiprecision.html @@ -0,0 +1,364 @@ + + + +Using Boost.Multiprecision + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ All new projects are recommended to use Boost.Multiprecision. +

+
+ + Using + Boost.Multiprecision cpp_float + for numerical calculations with high precision. +
+

+ The Boost.Multiprecision library can be used for computations requiring precision + exceeding that of standard built-in types such as float, double and long + double. For extended-precision calculations, Boost.Multiprecision supplies + a template data type called cpp_dec_float. The number of decimal digits of + precision is fixed at compile-time via template parameter. +

+

+ To use these floating-point types and constants, we need some includes: +

+
#include <boost/math/constants/constants.hpp>
+
+#include <boost/multiprecision/cpp_dec_float.hpp>
+// using boost::multiprecision::cpp_dec_float
+
+#include <iostream>
+#include <limits>
+
+

+ So now we can demonstrate with some trivial calculations: +

+
int main()
+{
+
+

+ Using typedef cpp_dec_float_50 + hides the complexity of multiprecision to allow us to define variables with + 50 decimal digit precision just like built-in double. +

+
using boost::multiprecision::cpp_dec_float_50;
+
+cpp_dec_float_50 seventh = cpp_dec_float_50(1) / 7;
+
+

+ By default, output would only show the standard 6 decimal digits, so set + precision to show all 50 significant digits. +

+
std::cout.precision(std::numeric_limits<cpp_dec_float_50>::digits10);
+std::cout << seventh << std::endl;
+
+

+ which outputs: +

+
0.14285714285714285714285714285714285714285714285714
+
+

+ We can also use constants, guaranteed to be initialized with the very last + bit of precision. +

+
cpp_dec_float_50 circumference = boost::math::constants::pi<cpp_dec_float_50>() * 2 * seventh;
+
+std::cout << circumference << std::endl;
+
+

+ which outputs +

+
0.89759790102565521098932668093700082405633411410717
+
+
+ + Using + Boost.Multiprecision to generate a high-precision array of sin coefficents + for use with FFT. +
+

+ The Boost.Multiprecision library can be used for computations requiring precision + exceeding that of standard built-in types such as float, + double and long + double. For extended-precision calculations, + Boost.Multiprecision supplies a template data type called cpp_dec_float. + The number of decimal digits of precision is fixed at compile-time via template + parameter. +

+

+ To use these floating-point types and constants, we need some includes: +

+
#include <boost/math/constants/constants.hpp>
+// using boost::math::constants::pi;
+
+#include <boost/multiprecision/cpp_dec_float.hpp>
+// using boost::multiprecision::cpp_dec_float
+
+#include <iostream>
+#include <limits>
+#include <vector>
+#include <algorithm>
+#include <iomanip>
+#include <iterator>
+#include <fstream>
+
+

+ Define a text string which is a C++ comment with the program licence, copyright + etc. You could of course, tailor this to your needs, including your copyright + claim. There are versions of array + provided by Boost.Array in boost::array + or the C++11 std::array, but since not all platforms provide C++11 support, + this program provides the Boost version as fallback. +

+
static const char* prolog =
+{
+  "// Use, modification and distribution are subject to the\n"
+  "// Boost Software License, Version 1.0.\n"
+  "// (See accompanying file LICENSE_1_0.txt\n"
+  "// or copy at ""http://www.boost.org/LICENSE_1_0.txt)\n\n"
+
+  "// Copyright ???? 2013.\n\n"
+
+  "// Use boost/array if std::array (C++11 feature) is not available.\n"
+  "#ifdef  BOOST_NO_CXX11_HDR_ARRAY\n"
+  "#include <boost/array/array.hpp>\n"
+  "#else\n"
+  "#include <array>\n"
+  "#endif\n\n"
+};
+
+
+using boost::multiprecision::cpp_dec_float_50;
+using boost::math::constants::pi;
+// VS 2010 (wrongly) requires these at file scope, not local scope in `main`.
+// This program also requires `-std=c++11` option to compile using Clang and GCC.
+
+int main()
+{
+
+

+ One often needs to compute tables of numbers in mathematical software. +

+

+ A fast Fourier transform (FFT), for example, may use a table of the values + of sin((π/2n) in its implementation details. In order to maximize the precision + in the FFT implementation, the precision of the tabulated trigonometric values + should exceed that of the built-in floating-point type used in the FFT. +

+

+ The sample below computes a table of the values of sin(π/2n) in the range + 1 <= n <= 31. +

+

+ This program makes use of, among other program elements, the data type boost::multiprecision::cpp_dec_float_50 for a precision of 50 + decimal digits from Boost.Multiprecision, the value of constant π retrieved + from Boost.Math, guaranteed to be initialized with the very last bit of precision + for the type, here cpp_dec_float_50, + and a C++11 lambda function combined with std::for_each(). +

+

+ define the number of values in the array. +

+
std::size_t size = 32U;
+cpp_dec_float_50 p = pi<cpp_dec_float_50>();
+cpp_dec_float_50 p2 = boost::math::constants::pi<cpp_dec_float_50>();
+
+std::vector <cpp_dec_float_50> sin_values (size);
+unsigned n = 1U;
+// Generate the sine values.
+std::for_each
+(
+  sin_values.begin (),
+  sin_values.end (),
+  [&n](cpp_dec_float_50& y)
+  {
+    y = sin( pi<cpp_dec_float_50>() / pow(cpp_dec_float_50 (2), n));
+    ++n;
+  }
+);
+
+

+ Define the floating-point type for the generated file, either built-in double, float, + or long double, + or a user defined type like cpp_dec_float_50. +

+
std::string fp_type = "double";
+
+std::cout << "Generating an `std::array` or `boost::array` for floating-point type: "
+  << fp_type << ". " << std::endl;
+
+

+ By default, output would only show the standard 6 decimal digits, so set + precision to show enough significant digits for the chosen floating-point + type. For cpp_dec_float_50 + is 50. (50 decimal digits should be ample for most applications). +

+
std::streamsize precision = std::numeric_limits<cpp_dec_float_50>::digits10;
+
+//  std::cout.precision(std::numeric_limits<cpp_dec_float_50>::digits10);
+std::cout << precision << " decimal digits precision. " << std::endl;
+
+

+ Of course, one could also choose less, for example, 36 would be sufficient + for the most precise current long + double implementations using 128-bit. + In general, it should be a couple of decimal digits more (guard digits) than + std::numeric_limits<RealType>::max_digits10 for the target system floating-point + type. If the implementation does not provide max_digits10, + the the Kahan formula std::numeric_limits<RealType>::digits + * 3010/10000 + + 2 can be used instead. +

+

+ The compiler will read these values as decimal digits strings and use the + nearest representation for the floating-point type. +

+

+ Now output all the sine table, to a file of your chosen name. +

+
  const char sines_name[] = "sines.hpp";  // In same directory as .exe
+
+  std::ofstream fout(sines_name, std::ios_base::out);  // Creates if no file exists,
+  // & uses default overwrite/ ios::replace.
+  if (fout.is_open() == false)
+  {  // failed to open OK!
+    std::cout << "Open file " << sines_name << " failed!" << std::endl;
+    return EXIT_FAILURE;
+  }
+  else
+  {
+    std::cout << "Open file " << sines_name << " for output OK." << std::endl;
+    fout << prolog << "// Table of " << sin_values.size() << " values with "
+      << precision << " decimal digits precision,\n"
+      "// generated by program fft_sines_table.cpp.\n" << std::endl;
+
+    fout <<
+"#ifdef BOOST_NO_CXX11_HDR_ARRAY""\n"
+ "  static const boost::array<double, " << size << "> sines =\n"
+"#else""\n"
+"  static const std::array<double, " << size << "> sines =\n"
+"#endif""\n"
+    "{{\n"; // 2nd { needed for some GCC compiler versions.
+    fout.precision(precision);
+
+    for (unsigned int i = 0U; ;)
+    {
+      fout << "  " << sin_values[i];
+      if (i == sin_values.size()-1)
+      { // next is last value.
+        fout << "\n}};\n"; // 2nd } needed for some earlier GCC compiler versions.
+        break;
+      }
+      else
+      {
+        fout << ",\n";
+        i++;
+      }
+    }
+
+    fout.close();
+    std::cout << "Close file " << sines_name << " for output OK." << std::endl;
+
+  }
+
+

+ The output file generated can be seen at ../../example/sines.hpp +

+

+ The table output is: +

+
The printed table is:
+
+  1
+  0.70710678118654752440084436210484903928483593768847
+  0.38268343236508977172845998403039886676134456248563
+  0.19509032201612826784828486847702224092769161775195
+  0.098017140329560601994195563888641845861136673167501
+  0.049067674327418014254954976942682658314745363025753
+  0.024541228522912288031734529459282925065466119239451
+  0.012271538285719926079408261951003212140372319591769
+  0.0061358846491544753596402345903725809170578863173913
+  0.003067956762965976270145365490919842518944610213452
+  0.0015339801862847656123036971502640790799548645752374
+  0.00076699031874270452693856835794857664314091945206328
+  0.00038349518757139558907246168118138126339502603496474
+  0.00019174759731070330743990956198900093346887403385916
+  9.5873799095977345870517210976476351187065612851145e-05
+  4.7936899603066884549003990494658872746866687685767e-05
+  2.3968449808418218729186577165021820094761474895673e-05
+  1.1984224905069706421521561596988984804731977538387e-05
+  5.9921124526424278428797118088908617299871778780951e-06
+  2.9960562263346607504548128083570598118251878683408e-06
+  1.4980281131690112288542788461553611206917585861527e-06
+  7.4901405658471572113049856673065563715595930217207e-07
+  3.7450702829238412390316917908463317739740476297248e-07
+  1.8725351414619534486882457659356361712045272098287e-07
+  9.3626757073098082799067286680885620193236507169473e-08
+  4.681337853654909269511551813854009695950362701667e-08
+  2.3406689268274552759505493419034844037886207223779e-08
+  1.1703344634137277181246213503238103798093456639976e-08
+  5.8516723170686386908097901008341396943900085051757e-09
+  2.9258361585343193579282304690689559020175857150074e-09
+  1.4629180792671596805295321618659637103742615227834e-09
+*/
+
+

+ The output can be copied as text and readily integrated into a given source + code. Alternatively, the output can be written to a text or even be used + within a self-written automatic code generator as this example. +

+

+ A computer algebra system can be used to verify the results obtained from + Boost.Math and Boost.Multiprecision. For example, the Wolfram + Mathematica computer algebra system can obtain a similar table with + the command: +

+
Table[N[Sin[Pi / (2^n)], 50], {n, 1, 31, 1}]
+
+

+ The Wolfram Alpha computational + knowledge engine can also be used to generate this table. The same command + can be pasted into the compute box. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/use_ntl.html b/boost/libs/math/doc/html/math_toolkit/high_precision/use_ntl.html new file mode 100644 index 00000000..4c645152 --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/use_ntl.html @@ -0,0 +1,74 @@ + + + +Using NTL Library + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ NTL::RR (an arbitrarily-fixed + precision floating-point number type), can be used via the bindings in boost/math/bindings/rr.hpp. + For details, see NTL: A Library for doing + Number Theory by Victor Shoup. +

+

+ New projects are recommended to use Boost.Multiprecision + instead. +

+

+ Unfortunately NTL::RR doesn't quite satisfy our conceptual + requirements, so there is a very thin wrapper class boost::math::ntl::RR defined in boost/math/bindings/rr.hpp + that you should use in place of NTL::RR. The + class is intended to be a drop-in replacement for the "real" NTL::RR + that adds some syntactic sugar to keep this library happy, plus some of the + standard library functions not implemented in NTL. +

+

+ For those functions that are based upon the Lanczos + approximation, the bindings defines a series of approximations with + up to 61 terms and accuracy up to approximately 3e-113. This therefore sets + the upper limit for accuracy to the majority of functions defined this library + when used with NTL::RR. +

+

+ There is a concept checking test program for NTL support here. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/using_test.html b/boost/libs/math/doc/html/math_toolkit/high_precision/using_test.html new file mode 100644 index 00000000..d5b886cf --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/using_test.html @@ -0,0 +1,144 @@ + + + +Using without expression templates for Boost.Test and others + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ As noted in the Boost.Multiprecision + documentation, certain program constructs will not compile when using expression + templates. One example that many users may encounter is Boost.Test (1.54 + and earlier) when using macro BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION. +

+

+ If, for example, you wish to use any multiprecision type like cpp_dec_float_50 in place of double to give more precision, you will need + to override the default boost::multiprecision::et_on + with boost::multiprecision::et_off. +

+
#include <boost/multiprecision/cpp_dec_float.hpp>
+
+

+ To define a 50 decimal digit type using cpp_dec_float, + you must pass two template parameters to boost::multiprecision::number. +

+

+ It may be more legible to use a two-staged type definition such as this: +

+
typedef boost::multiprecision::cpp_dec_float<50> mp_backend;
+typedef boost::multiprecision::number<mp_backend, boost::multiprecision::et_off> cpp_dec_float_50_noet;
+
+

+ Here, we first define mp_backend + as cpp_dec_float with 50 + digits. The second step passes this backend to boost::multiprecision::number + with boost::multiprecision::et_off, an enumerated type. +

+
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off>
+cpp_dec_float_50_noet;
+
+

+ You can reduce typing with a using + directive using namespace + boost::multiprecision; + if desired, as shown below. +

+
using namespace boost::multiprecision;
+
+

+ Now cpp_dec_float_50_noet + or cpp_dec_float_50_et can + be used as a direct replacement for built-in types like double + etc. +

+
BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_noet)
+{ // No expression templates/
+  typedef number<cpp_dec_float<50>, et_off> cpp_dec_float_50_noet;
+
+  std::cout.precision(std::numeric_limits<cpp_dec_float_50_noet>::digits10); // All significant digits.
+  std::cout << std::showpoint << std::endl; // Show trailing zeros.
+
+  cpp_dec_float_50_noet a ("1.0");
+  cpp_dec_float_50_noet b ("1.0");
+  b += std::numeric_limits<cpp_dec_float_50_noet>::epsilon(); // Increment least significant decimal digit.
+
+  cpp_dec_float_50_noet eps = std::numeric_limits<cpp_dec_float_50_noet>::epsilon();
+
+  std::cout <<"a = " << a << ",\nb = " << b << ",\neps = " << eps << std::endl;
+
+  BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
+  BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
+
+
+
+} // BOOST_AUTO_TEST_CASE(cpp_float_test_check_close)
+
+BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_et)
+{ // Using expression templates.
+  typedef number<cpp_dec_float<50>, et_on> cpp_dec_float_50_et;
+
+  std::cout.precision(std::numeric_limits<cpp_dec_float_50_et>::digits10); // All significant digits.
+  std::cout << std::showpoint << std::endl; // Show trailing zeros.
+
+  cpp_dec_float_50_et a("1.0");
+  cpp_dec_float_50_et b("1.0");
+  b += std::numeric_limits<cpp_dec_float_50_et>::epsilon(); // Increment least significant decimal digit.
+
+  cpp_dec_float_50_et eps = std::numeric_limits<cpp_dec_float_50_et>::epsilon();
+
+  std::cout << "a = " << a << ",\nb = " << b << ",\neps = " << eps << std::endl;
+
+  BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
+  BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
+
+

+ Using cpp_dec_float_50 with + the default expression template use switched on, the compiler error message + for `BOOST_CHECK_CLOSE_FRACTION(a, b, eps); would be: +

+
// failure floating_point_comparison.hpp(59): error C2440: 'static_cast' :
+// cannot convert from 'int' to 'boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4>'
+
+

+ A full example code is at test_cpp_float_close_fraction.cpp +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/high_precision/why_high_precision.html b/boost/libs/math/doc/html/math_toolkit/high_precision/why_high_precision.html new file mode 100644 index 00000000..5ff2b0dc --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/high_precision/why_high_precision.html @@ -0,0 +1,139 @@ + + + +Why use a high-precision library rather than built-in floating-point types? + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ For nearly all applications, the built-in floating-point types, double (and long + double if this offers higher precision + than double) offer enough precision, + typically a dozen decimal digits. +

+

+ Some reasons why one would want to use a higher precision: +

+
    +
  • + A much more precise result (many more digits) is just a requirement. +
  • +
  • + The range of the computed value exceeds the range of the type: factorials + are the textbook example. +
  • +
  • + Using double is (or may + be) too inaccurate. +
  • +
  • + Using long double + (or may be) is too inaccurate. +
  • +
  • + Using an extended-precision type implemented in software as double-double + (Darwin) + is sometimes unpredictably inaccurate. +
  • +
  • + Loss of precision or inaccuracy caused by extreme arguments or cancellation + error. +
  • +
  • + An accuracy as good as possible for a chosen built-in floating-point + type is required. +
  • +
  • + As a reference value, for example, to determine the inaccuracy of a value + computed with a built-in floating point type, (perhaps even using some + quick'n'dirty algorithm). The accuracy of many functions and distributions + in Boost.Math has been measured in this way from tables of very high + precision (up to 1000 decimal digits). +
  • +
+

+ Many functions and distributions have differences from exact values that + are only a few least significant bits - computation noise. Others, often + those for which analytical solutions are not available, require approximations + and iteration: these may lose several decimal digits of precision. +

+

+ Much larger loss of precision can occur for boundary + or corner cases, + often caused by cancellation + errors. +

+

+ (Some of the worst and most common examples of cancellation + error or loss of significance can be avoided by using complements: + see why complements?). +

+

+ If you require a value which is as accurate as can be represented in the + floating-point type, and is thus the closest representable value and has + an error less than 1/2 a least + significant bit or ulp + it may be useful to use a higher-precision type, for example, cpp_dec_float_50, to generate this value. + Conversion of this value to a built-in floating-point type ('float', double or long + double) will not cause any further + loss of precision. A decimal digit string will also be 'read' precisely by + the compiler into a built-in floating-point type to the nearest representable + value. +

+
+ + + + + +
[Note]Note

+ In contrast, reading a value from an std::istream + into a built-in floating-point type is not guaranteed + by the C++ Standard to give the nearest representable value. +

+

+ William Kahan coined the term Table-Maker's + Dilemma for the problem of correctly rounding functions. Using a + much higher precision (50 or 100 decimal digits) is a practical way of generating + (almost always) correctly rounded values. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + -- cgit v1.2.3