CAPD DynSys Library
5.2.0
|
To use multiple-precision you need to install packages
They can be also compiled and installed from sources even under Windows, but in this tutorial we assume for simplicity that you are under Linux.
The configure script will automatically detect those libraries and compile mpcapd library (multiple precision version of the CAPD library).
The CAPD library uses generic programming (templates) therefore switching from double precision to multiple precision is really simple. You only have to replace the base building blocs (types) of the CAPD classes.
Use capd::multiPrec::MpReal instead of double. MpReal is a C++ class which represents multiple-precision floating point number with correct rounding.
To define multiple-precision interval you can write
Then in your code use MpInterval
instead of DInterval
(interval with double precision endpoints). To define MpInterval
include capd/intervals/MpInterval.h instead of DoubleInterval.h or Interval.h.
If you use typedef's in your programs then most probably you need to change only two lines.
The following examples shows how to define multiple-precision variables, initiate them and use them as base types for other CAPD classes: Interval, Vector and Function.
These examples can be found in the capd/capdDynSys/examples/multiprecExample directory.
To compile first example one can invoke:
where CAPD_DIR is a root directory of the CAPD library or directory to which the CAPD library was installed.
You can also use provided Makefile and simply call
First we include definition of MpReal and define shorter name MpFloat
Then we set precision to 100 mantisa bits (about 30 decimal digits)
and we set MpFloat to round numbers to the nearest representable.
Now we create several MpFloat objects using different possible constructors
and print them on a screen
Instead of including a lot of header files, "building" your own types and defining new names for them (using typedef), you can include just one header file
and use types which are included in the mpcapd library. It lets you to start writing your code without repeating every time the same tedious things (i.e. including a lot of files and making many typedefs). It also shorten compilation time, because they are not recompiled when your program is built.
In general names defined in the mpcapd library agree with those defined in examples above, with one difference: they are defined in the capd
namespace. Therefore you can simply replace all "includes" and "typedefs" in the above examples by two lines
and they should compile and work exactly the same.
The naming convention is as follows:
MpFloat
is the name of the base multiple precision type,CLASS
is the name of the template class then the name of a multiple precision type will beMpCLASS
for "nonrigorous" type MpICLASS
for rigorous, interval typeRemark: Not all possible templates are compiled into mpcapd library e.g vectors of a fixed size are not included. Instead we include only those that are often used. The list of types and their names can be found in the mplib.h
file in the "include" directory of the corresponding module (e.g. capd/include/intervals/mplib.h
).