mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-07-21 13:23:49 +00:00
Fix mistakes (#729)
* Update Jamfile.v2 * Update introduction.qbk * Update tutorial.qbk * Update tutorial_cpp_int.qbk * Update tutorial_gmp_int.qbk * Update tutorial_tommath.qbk * Update integer_examples.cpp * Update tutorial_cpp_bin_float.qbk * Update tutorial_cpp_dec_float.qbk * Update tutorial_gmp_float.qbk * Update tutorial_mpfr_float.qbk * Update tutorial_float128.qbk * Update tutorial_float_builtin_ctor.qbk * Update big_seventh.cpp * Update tutorial_float_eg.qbk * Update floating_point_examples.cpp * Update mpfr_precision.cpp * Update gauss_laguerre_quadrature.cpp * Update tutorial_interval_mpfi.qbk * Update tutorial_cpp_complex.qbk * Update tutorial_mpc_complex.qbk * Update tutorial_float128_complex.qbk * Update tutorial_complex_adaptor.qbk * Update tutorial_rational.qbk * Update tutorial_tommath_rational.qbk * Update tutorial_logged_adaptor.qbk * Update tutorial_debug_adaptor.qbk * Update tutorial_visualizers.qbk * Update tutorial_fwd.qbk * Update tutorial_conversions.qbk * Update tutorial_random.qbk * Update random_snips.cpp * Update tutorial_constexpr.qbk * Update tutorial_import_export.qbk * Update cpp_int_import_export.cpp * Update tutorial_mixed_precision.qbk * Update tutorial_variable_precision.qbk * Update scoped_precision_example.cpp * Update tutorial_numeric_limits.qbk * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_io.qbk * Update reference_number.qbk * Update reference_cpp_bin_float.qbk * Update reference_cpp_double_fp_backend.qbk * Update reference_internal_support.qbk * Update reference_backend_requirements.qbk * Update performance.qbk * Update performance_overhead.qbk * Update performance_real_world.qbk * Update performance_integer_real_world.qbk * Update performance_rational_real_world.qbk * Update reference_number.qbk * Update tutorial_numeric_limits.qbk * Update reference_backend_requirements.qbk
This commit is contained in:
@@ -71,7 +71,7 @@ allows us to define variables with 50 decimal digit precision just like __fundam
|
||||
|
||||
0.14285714285714285714285714285714285714285714285714
|
||||
|
||||
We can also use Boost.Math __math_constants like [pi],
|
||||
We can also use __math_constants like [pi],
|
||||
guaranteed to be initialized with the very last bit of precision for the floating-point type.
|
||||
*/
|
||||
std::cout << "pi = " << boost::math::constants::pi<cpp_bin_float_50>() << std::endl;
|
||||
@@ -140,7 +140,7 @@ but if one is implementing a formula involving a fraction from integers,
|
||||
including decimal fractions like 1/10, 1/100, then comparison with other computations like __WolframAlpha
|
||||
will reveal differences whose cause may be perplexing.
|
||||
|
||||
To get as precise-as-possible decimal fractions like 1.234, we can write
|
||||
To get as-precise-as-possible decimal fractions like 1.234, we can write
|
||||
*/
|
||||
|
||||
const cpp_bin_float_50 f1(cpp_bin_float_50(1234) / 1000); // Construct from a fraction.
|
||||
|
||||
@@ -28,7 +28,7 @@ int main()
|
||||
using boost::multiprecision::cpp_int;
|
||||
// Create a cpp_int with just a couple of bits set:
|
||||
cpp_int i;
|
||||
bit_set(i, 5000); // set the 5000'th bit
|
||||
bit_set(i, 5000); // set the 5000th bit
|
||||
bit_set(i, 200);
|
||||
bit_set(i, 50);
|
||||
// export into 8-bit unsigned values, most significant bit first:
|
||||
|
||||
@@ -121,8 +121,8 @@ Which outputs:
|
||||
|
||||
[pre 9.82266396479604757017335009796882833995903762577173e-01]
|
||||
|
||||
Now that we've seen some non-template examples, lets repeat the code again, but this time as a template
|
||||
that can be called either with a builtin type (`float`, `double` etc), or with a multiprecision type:
|
||||
Now that we've seen some non-template examples, let's repeat the code again, but this time as a template
|
||||
that can be called either with a builtin type (`float`, `double` etc.), or with a multiprecision type:
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// of this example) could be used for smaller arguments.
|
||||
|
||||
// This example has been tested with decimal digits counts
|
||||
// ranging from 21...301, by adjusting the parameter
|
||||
// ranging from 21 to 301, by adjusting the parameter
|
||||
// local::my_digits10 at compile time.
|
||||
|
||||
// References:
|
||||
|
||||
@@ -52,12 +52,12 @@ void print_factorials()
|
||||
factorial *= i;
|
||||
}
|
||||
//
|
||||
// Lets see how many digits the largest factorial was:
|
||||
// Let's see how many digits the largest factorial was:
|
||||
unsigned digits = results.back().str().size();
|
||||
//
|
||||
// Now print them out, using right justification, while we're at it
|
||||
// we'll indicate the limit of each integer type, so begin by defining
|
||||
// the limits for 16, 32, 64 etc bit integers:
|
||||
// the limits for 16, 32, 64 etc. bit integers:
|
||||
cpp_int limits[] = {
|
||||
(cpp_int(1) << 16) - 1,
|
||||
(cpp_int(1) << 32) - 1,
|
||||
|
||||
@@ -12,12 +12,12 @@ beta distribution to an absurdly high precision and compare the
|
||||
accuracy and times taken for various methods. That is, we want
|
||||
to calculate the value of `x` for which ['I[sub x](a, b) = 0.5].
|
||||
|
||||
Ultimately we'll use Newtons method and set the precision of
|
||||
Ultimately we'll use Newton's method and set the precision of
|
||||
mpfr_float to have just enough digits at each iteration.
|
||||
|
||||
The full source of the this program is in [@../../example/mpfr_precision.cpp]
|
||||
The full source of this program is in [@../../example/mpfr_precision.cpp].
|
||||
|
||||
We'll skip over the #includes and using declations, and go straight to
|
||||
We'll skip over the #includes and using declarations, and go straight to
|
||||
some support code, first off a simple stopwatch for performance measurement:
|
||||
|
||||
*/
|
||||
@@ -106,11 +106,11 @@ We'll begin with a reference method that simply calls the Boost.Math function `i
|
||||
full working precision of the arguments throughout. Our reference function takes 3 arguments:
|
||||
|
||||
* The 2 parameters `a` and `b` of the beta distribution, and
|
||||
* The number of decimal digits precision to achieve in the result.
|
||||
* the number of decimal digits precision to achieve in the result.
|
||||
|
||||
We begin by setting the default working precision to that requested, and then, since we don't know where
|
||||
our arguments `a` and `b` have been or what precision they have, we make a copy of them - note that since
|
||||
copying also copies the precision as well as the value, we have to set the precision expicitly with a
|
||||
copying also copies the precision as well as the value, we have to set the precision explicitly with a
|
||||
second argument to the copy. Then we can simply return the result of `ibeta_inv`:
|
||||
*/
|
||||
mpfr_float beta_distribution_median_method_1(mpfr_float const& a_, mpfr_float const& b_, unsigned digits10)
|
||||
@@ -120,8 +120,8 @@ mpfr_float beta_distribution_median_method_1(mpfr_float const& a_, mpfr_float co
|
||||
return ibeta_inv(a, b, half);
|
||||
}
|
||||
/*`
|
||||
You be wondering why we needed to change the precision of our variables `a` and `b` as well as setting the default -
|
||||
there are in fact two ways in which this can go wrong if we don't do that:
|
||||
You may be wondering why we needed to change the precision of our variables `a` and `b` as well as setting the
|
||||
default - there are in fact two ways in which this can go wrong if we don't do that:
|
||||
|
||||
* The variables have too much precision - this will cause all arithmetic operations involving those types to be
|
||||
promoted to the higher precision wasting precious calculation time.
|
||||
|
||||
@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
|
||||
double write = 2./3; // Any arbitrary value that cannot be represented exactly.
|
||||
double read = 0;
|
||||
std::stringstream s;
|
||||
s.precision(std::numeric_limits<double>::digits10); // or `float64_t` for 64-bit IEE754 double.
|
||||
s.precision(std::numeric_limits<double>::digits10); // or `float64_t` for 64-bit IEEE 754 double.
|
||||
s << write;
|
||||
s >> read;
|
||||
if(read != write)
|
||||
@@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
|
||||
}
|
||||
{
|
||||
//[max_digits10_4
|
||||
/*`and similarly for a much higher precision type:
|
||||
/*`And similarly for a much higher precision type:
|
||||
*/
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
@@ -392,7 +392,7 @@ so the default expression template parameter has been replaced by `et_off`.]
|
||||
|
||||
cpp_bin_float_quad expected = NaN;
|
||||
cpp_bin_float_quad calculated = 2 * NaN;
|
||||
// Comparisons of NaN's always fail:
|
||||
// Comparisons of NaNs always fail:
|
||||
bool b = expected == calculated;
|
||||
std::cout << b << std::endl;
|
||||
BOOST_CHECK_NE(expected, expected);
|
||||
@@ -445,7 +445,7 @@ Then we can equally well use a multiprecision type cpp_bin_float_quad:
|
||||
infinity output was inf
|
||||
infinity input was inf
|
||||
``
|
||||
Similarly we can do the same with NaN (except that we cannot use `assert` (because any comparisons with NaN always return false).
|
||||
Similarly we can do the same with NaN (except that we cannot use `assert` (because any comparisons with NaN always return false)).
|
||||
*/
|
||||
{
|
||||
std::locale old_locale;
|
||||
|
||||
@@ -195,7 +195,7 @@ void t4()
|
||||
using namespace boost::multiprecision;
|
||||
using namespace boost::random;
|
||||
//
|
||||
// Generate some distruted values:
|
||||
// Generate some distributed values:
|
||||
//
|
||||
uniform_real_distribution<cpp_bin_float_50> ur(-20, 20);
|
||||
gamma_distribution<cpp_bin_float_50> gd(20);
|
||||
@@ -277,7 +277,7 @@ void t5()
|
||||
// Generate some multiprecision values, note that the generator is so large
|
||||
// that we have to allocate it on the heap, otherwise we may run out of
|
||||
// stack space! We could avoid this by using a floating point type which
|
||||
// allocates it's internal storage on the heap - cpp_bin_float will do
|
||||
// allocates its internal storage on the heap - cpp_bin_float will do
|
||||
// this with the correct template parameters, as will the GMP or MPFR
|
||||
// based reals.
|
||||
//
|
||||
|
||||
@@ -21,14 +21,14 @@ can be displayed in your debugger of choice:
|
||||
using mp_t = boost::multiprecision::debug_adaptor_t<boost::multiprecision::mpfr_float>;
|
||||
|
||||
/*`
|
||||
Our first example will investigate calculating the Bessel J function via it's well known
|
||||
Our first example will investigate calculating the Bessel J function via its well known
|
||||
series representation:
|
||||
|
||||
[$../bessel2.svg]
|
||||
|
||||
This simple series suffers from catastrophic cancellation error
|
||||
near the roots of the function, so we'll investigate slowly increasing the precision of
|
||||
the calculation until we get the result to N-decimal places. We'll begin by defining
|
||||
the calculation until we get the result to N decimal places. We'll begin by defining
|
||||
a function to calculate the series for Bessel J, the details of which we'll leave in the
|
||||
source code:
|
||||
*/
|
||||
@@ -158,11 +158,11 @@ mp_t Bessel_J_to_precision(mp_t v, mp_t x, unsigned digits10)
|
||||
}
|
||||
//
|
||||
// We now have an accurate result, but it may have too many digits,
|
||||
// so lets round the result to the requested precision now:
|
||||
// so let's round the result to the requested precision now:
|
||||
//
|
||||
result.precision(saved_digits10);
|
||||
//
|
||||
// To maintain uniform precision during function return, lets
|
||||
// To maintain uniform precision during function return, let's
|
||||
// reset the default precision now:
|
||||
//
|
||||
scoped.reset(saved_digits10);
|
||||
@@ -173,7 +173,7 @@ mp_t Bessel_J_to_precision(mp_t v, mp_t x, unsigned digits10)
|
||||
So far, this is all well and good, but there is still a potential trap for the unwary here,
|
||||
when the function returns the variable [/result] may be copied/moved either once or twice
|
||||
depending on whether the compiler implements the named-return-value optimisation. And since this
|
||||
all happens outside the scope of this function, the precision of the returned value may get unexpected
|
||||
all happens outside the scope of this function, the precision of the returned value may get unexpectedly
|
||||
changed - and potentially with different behaviour once optimisations are turned on!
|
||||
|
||||
To prevent these kinds of unintended consequences, a function returning a value with specified precision
|
||||
@@ -328,7 +328,7 @@ mp_t reduce_n_pi(const mp_t& arg)
|
||||
scope_2.reset(boost::multiprecision::variable_precision_options::preserve_target_precision);
|
||||
mp_t result = reduced;
|
||||
//
|
||||
// As with previous examples, returning the result may create temporaries, so lets
|
||||
// As with previous examples, returning the result may create temporaries, so let's
|
||||
// make sure that we preserve the precision of result. Note that this isn't strictly
|
||||
// required if the calling context is always of uniform precision, but we can't be sure
|
||||
// of our calling context:
|
||||
|
||||
Reference in New Issue
Block a user