The Finite Resolution Dynamics Software
opensqr.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// @file opensqr.h
4 ///
5 /// An open-interval version of the square function.
6 /// This file contains the definition of the square function f (x) = x^2
7 /// in the interval arithmetic based on open intervals,
8 /// as opposed to closed intervals.
9 ///
10 /// @author Pawel Pilarczyk
11 ///
12 /////////////////////////////////////////////////////////////////////////////
13 
14 // Copyright (C) 2007-2010 by Pawel Pilarczyk.
15 //
16 // This file is part of my research program package. This is free software;
17 // you can redistribute it and/or modify it under the terms of the GNU
18 // General Public License as published by the Free Software Foundation;
19 // either version 2 of the License, or (at your option) any later version.
20 //
21 // This software is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License along
27 // with this software; see the file "license.txt". If not, write to the
28 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 // MA 02111-1307, USA.
30 
31 // Started on March 19, 2009. Last revision: March 19, 2009.
32 
33 
34 #ifndef _FINRESDYN_OPENSQR_H_
35 #define _FINRESDYN_OPENSQR_H_
36 
37 
38 // include local header files
39 #include "rounding.h"
40 
41 
42 // --------------------------------------------------
43 // ------ a function that computes the square -------
44 // --------------------------------------------------
45 
46 /// Computes the square f (x) = x^2 in the open interval arithmetic.
47 template <class NumType>
48 void openSqr (const NumType &xLeft, const NumType &xRight,
49  NumType &yLeft, NumType &yRight)
50 {
51  // extract the rounding class to shorten the notation
52  typedef tRounding<NumType> rnd;
53 
54  // make sure the input interval is correct
55  if (xLeft >= xRight)
56  throw "Wrong input interval for openSqr.";
57 
58  if (xLeft >= 0)
59  {
60  yLeft = rnd::mul_down (xLeft, xLeft);
61  yRight = rnd::mul_up (xRight, xRight);
62  }
63  else if (xRight <= 0)
64  {
65  yLeft = rnd::mul_down (xRight, xRight);
66  yRight = rnd::mul_up (xLeft, xLeft);
67  }
68  else
69  {
70  yLeft = -rnd::min_number ();
71  yRight = (-xLeft < xRight) ? rnd::mul_up (xRight, xRight) :
72  rnd::mul_up (xLeft, xLeft);
73  }
74  return;
75 } /* openSqr */
76 
77 
78 #endif // _FINRESDYN_OPENSQR_H_
79 
void openSqr(const NumType &xLeft, const NumType &xRight, NumType &yLeft, NumType &yRight)
Computes the square f (x) = x^2 in the open interval arithmetic.
Definition: opensqr.h:48
Rigorous rounding of arithmetic operations.
A class for rounding operations which uses the BOOST library.
Definition: rounding.h:48