1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
[/
Copyright 2011 - 2020 John Maddock.
Copyright 2013 - 2019 Paul A. Bristow.
Copyright 2013 Christopher Kormanyos.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
]
[section:interval Interval Number Types]
There is one currently only one interval number type supported - [mpfi].
[section:mpfi mpfi_float]
`#include <boost/multiprecision/mpfi.hpp>`
namespace boost{ namespace multiprecision{
template <unsigned Digits10>
class mpfi_float_backend;
typedef number<mpfi_float_backend<50> > mpfi_float_50;
typedef number<mpfi_float_backend<100> > mpfifloat_100;
typedef number<mpfi_float_backend<500> > mpfifloat_500;
typedef number<mpfi_float_backend<1000> > mpfi_float_1000;
typedef number<mpfi_float_backend<0> > mpfi_float;
}} // namespaces
The `mpfi_float_backend` type is used in conjunction with `number`: It acts as a thin wrapper around the [mpfi] `mpfi_t`
to provide an real-number type that is a drop-in replacement for the native C++ floating-point types, but with
much greater precision and implementing interval arithmetic.
Type `mpfi_float_backend` can be used at fixed precision by specifying a non-zero `Digits10` template parameter, or
at variable precision by setting the template argument to zero. The `typedef`s `mpfi_float_50`, `mpfi_float_100`,
`mpfi_float_500`, `mpfi_float_1000` provide arithmetic types at 50, 100, 500 and 1000 decimal digits precision
respectively. The `typedef mpfi_float` provides a variable precision type whose precision can be controlled via theF
`number`s member functions.
[note This type only provides `numeric_limits` support when the precision is fixed at compile time.]
As well as the usual conversions from arithmetic and string types, instances of `number<mpfi_float_backend<N> >` are
copy constructible and assignable from:
* The [mpfi] native type `mpfi_t`.
* The `number` wrappers around [mpfi] or [mpfr]: `number<mpfi_float_backend<M> >` and `number<mpfr_float<M> >`.
* There is a two argument constructor taking two `number<mpfr_float<M> >` arguments specifying the interval.
It's also possible to access the underlying `mpfi_t` via the `data()` member function of `mpfi_float_backend`.
Things you should know when using this type:
* A default constructed `mpfi_float_backend` is set to zero (['Note that this is [*not] the default [mpfi] behavior]).
* No changes are made to [gmp] or [mpfr] global settings, so this type can coexist with existing
[mpfr] or [gmp] code.
* The code can equally use [mpir] in place of [gmp] - indeed that is the preferred option on Win32.
* This backend supports rvalue-references and is move-aware, making instantiations of `number` on this backend move aware.
* Conversion from a string results in a `std::runtime_error` being thrown if the string can not be interpreted
as a valid floating-point number.
* Division by zero results in an infinity.
There are some additional non member functions for working on intervals:
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfr_float_backend<Digits10>, ExpressionTemplates> lower(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val);
Returns the lower end of the interval.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfr_float_backend<Digits10>, ExpressionTemplates> upper(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val);
Returns the upper end of the interval.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfr_float_backend<Digits10>, ExpressionTemplates> median(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val);
Returns the mid point of the interval.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfr_float_backend<Digits10>, ExpressionTemplates> width(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val);
Returns the absolute width of the interval.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfi_float_backend<Digits10>, ExpressionTemplates> intersect(
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b);
Returns the interval which is the intersection of the ['a] and ['b]. Returns an
unspecified empty interval if there is no such intersection.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
number<mpfi_float_backend<Digits10>, ExpressionTemplates> hull(
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b);
Returns the interval which is the union of ['a] and ['b].
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool overlap(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b);
Returns `true` only if the intervals ['a] and ['b] overlap.
template <unsigned Digits10, expression_template_option ExpressionTemplates1, expression_template_option ExpressionTemplates2>
bool in(const number<mpfr_float_backend<Digits10>, ExpressionTemplates1>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates2>& b);
Returns `true` only if point ['a] is contained within the interval ['b].
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool zero_in(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a);
Returns `true` only if the interval ['a] contains the value zero.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool subset(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b);
Returns `true` only if ['a] is a subset of ['b].
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool proper_subset(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a,
const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b);
Returns `true` only if ['a] is a proper subset of ['b].
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool empty(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a);
Returns `true` only if ['a] is an empty interval, equivalent to `upper(a) < lower(a)`.
template <unsigned Digits10, expression_template_option ExpressionTemplates>
bool singleton(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a);
Returns `true` if `lower(a) == upper(a)`.
[h5 [mpfi] example:]
[mpfi_eg]
[endsect] [ section:mpfi mpfi_float]
[endsect] [/section:interval Interval Number Types]
|