The Conley-Morse Graphs Software
typeintv.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file typeintv.h
4///
5/// Data types for interval arithmetic.
6///
7/// @author Pawel Pilarczyk
8///
9/////////////////////////////////////////////////////////////////////////////
10
11// Copyright (C) 1997-2014 by Pawel Pilarczyk.
12//
13// This file is part of my research software package. This is free software:
14// you can redistribute it and/or modify it under the terms of the GNU
15// General Public License as published by the Free Software Foundation,
16// either version 3 of the License, or (at your option) any later version.
17//
18// This software is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this software; see the file "license.txt". If not,
25// please, see <https://www.gnu.org/licenses/>.
26
27// Started on October 20, 2008. Last revision: June 29, 2012.
28
29
30#ifndef _CMGRAPHS_TYPEINTV_H_
31#define _CMGRAPHS_TYPEINTV_H_
32
33
34#ifdef __USE_OLD_CAPD__
35
36// the interval arithmetic package from the CAPD library
37#include "capd/interval/DoubleInterval.h"
38
39/// The type of an interval (from the CAPD library 2.0).
40typedef capd::intervals::DoubleInterval IntervalType;
41
42#else
43
44// the interval arithmetic package from the CAPD library
45#include "capd/intervals/lib.h"
46#include "capd/rounding/DoubleRounding.h"
47
48/// The type of an interval (from the CAPD library 2.9/3.0 beta).
49typedef capd::DInterval IntervalType;
50
51#endif
52
53// include selected header files from the CHomP library
54#include "chomp/system/textfile.h"
55
56
57// --------------------------------------------------
58// ------ resetting the rounding if necessary -------
59// --------------------------------------------------
60
61/// This function resets rounding switches of the processor
62/// and sets rounding to the nearest.
63/// It is necessary in some cases, e.g., if the CAPD leaves
64/// incorrect rounding mode after doing some interval operations.
65inline void resetRounding ()
66{
67 capd::rounding::DoubleRounding::roundNearest ();
68 return;
69} /* resetRounding */
70
71
72// --------------------------------------------------
73// -------------- additional functions --------------
74// --------------------------------------------------
75
76/// Testing interval arithmetic.
77/// This simple function runs a very basic test on whether
78/// the interval arithmetic and the rounding directions work correctly.
79/// It returns 'true' if everything seems to be fine,
80/// or throws an exception (if requested to) or just returns 'false'
81/// if there is something obviously wrong with the interval arithmetic.
82inline bool testIntervals (bool throwException = false)
83{
84const char *warningMessage = "\
85* * * * * * * * * * * * * * * * WARNING * * * * * * * * * * * * * * * *\n\
86* It appears that switching the rounding mode in interval arithmetic\n\
87* doesn't work correctly. As a consequence, the results of computations\n\
88* will be inaccurate. In order to conduct mathematically correct rigorous\n\
89* computations, you should compile both the CAPD library and this software\n\
90* without optimization (remove the '-O2' switch from the makefile).\n\
91* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n";
92 IntervalType x (1.0, 1.0);
93 IntervalType x3 = x / 3;
95 if (x3. leftBound () < x3. rightBound ())
96 return true;
97 static bool warned = false;
98 if (throwException)
99 throw "Incorrect rounding in interval arithmetic.";
100 else if (!warned)
101 {
102 using chomp::homology::sout;
103 sout << warningMessage;
104 warned = true;
105 }
106 return false;
107} /* testIntervals */
108
109
110#endif // _CMGRAPHS_TYPEINTV_H_
111
void resetRounding()
This function resets rounding switches of the processor and sets rounding to the nearest.
Definition: typeintv.h:65
bool testIntervals(bool throwException=false)
Testing interval arithmetic.
Definition: typeintv.h:82
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Definition: typeintv.h:49