opensqr.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file opensqr.h
00004 ///
00005 /// An open-interval version of the square function.
00006 /// This file contains the definition of the square function f (x) = x^2
00007 /// in the interval arithmetic based on open intervals,
00008 /// as opposed to closed intervals.
00009 ///
00010 /// @author Pawel Pilarczyk
00011 ///
00012 /////////////////////////////////////////////////////////////////////////////
00013 
00014 // Copyright (C) 2007-2010 by Pawel Pilarczyk.
00015 //
00016 // This file is part of my research program package.  This is free software;
00017 // you can redistribute it and/or modify it under the terms of the GNU
00018 // General Public License as published by the Free Software Foundation;
00019 // either version 2 of the License, or (at your option) any later version.
00020 //
00021 // This software is distributed in the hope that it will be useful,
00022 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 // GNU General Public License for more details.
00025 //
00026 // You should have received a copy of the GNU General Public License along
00027 // with this software; see the file "license.txt".  If not, write to the
00028 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00029 // MA 02111-1307, USA.
00030 
00031 // Started on March 19, 2009. Last revision: March 19, 2009.
00032 
00033 
00034 #ifndef _FINRESDYN_OPENSQR_H_
00035 #define _FINRESDYN_OPENSQR_H_
00036 
00037 
00038 // include local header files
00039 #include "rounding.h"
00040 
00041 
00042 // --------------------------------------------------
00043 // ------ a function that computes the square -------
00044 // --------------------------------------------------
00045 
00046 /// Computes the square f (x) = x^2 in the open interval arithmetic.
00047 template <class NumType>
00048 void openSqr (const NumType &xLeft, const NumType &xRight,
00049         NumType &yLeft, NumType &yRight)
00050 {
00051         // extract the rounding class to shorten the notation
00052         typedef tRounding<NumType> rnd;
00053 
00054         // make sure the input interval is correct
00055         if (xLeft >= xRight)
00056                 throw "Wrong input interval for openSqr.";
00057 
00058         if (xLeft >= 0)
00059         {
00060                 yLeft = rnd::mul_down (xLeft, xLeft);
00061                 yRight = rnd::mul_up (xRight, xRight);
00062         }
00063         else if (xRight <= 0)
00064         {
00065                 yLeft = rnd::mul_down (xRight, xRight);
00066                 yRight = rnd::mul_up (xLeft, xLeft);
00067         }
00068         else
00069         {
00070                 yLeft = -rnd::min_number ();
00071                 yRight = (-xLeft < xRight) ? rnd::mul_up (xRight, xRight) :
00072                         rnd::mul_up (xLeft, xLeft);
00073         }
00074         return;
00075 } /* openSqr */
00076 
00077 
00078 #endif // _FINRESDYN_OPENSQR_H_
00079 

Generated on Mon Apr 12 15:09:57 2010 for The Finite Resolution Dynamics Software by  doxygen 1.5.3