Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/num/optype.h

Go to the documentation of this file.
00001 //  Copyright (C) 1998--2002  Petter Urkedal
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 
00027 //  $Id: optype.h,v 1.2 2002/09/01 12:02:18 petter_urkedal Exp $
00028 
00029 //  STATUS.  Only used in unmaintained matrixalgo.h and matrixtypes.h
00030 //  headers.
00031 
00032 #ifndef MORE_NUM_OPTYPE_H
00033 #define MORE_NUM_OPTYPE_H
00034 
00035 ///\if bits
00036 
00037 namespace more {
00038 namespace num {
00039 
00040 /*  This file defines operator result types for arithmetic types.  In
00041     most cases it may be sufficient to specialise the balanced_type
00042     template, as is done for the elementary types.
00043 
00044     These definitions are mostly intended for numerical algorithms.
00045     The support for integer types is therefore limited to the signed
00046     types.  The main function of this file is to define the templates,
00047     which elsewhere is specialized to matrix classes.  This makes it
00048     possible for algorithms to keep track of different representations 
00049     and of matrices.
00050 */
00051 
00052 
00053 
00054 //   I d e n t i t y   O b j e c t s
00055 
00056 
00057 template <class T> struct additive_identity {};
00058 
00059 template<> struct additive_identity<double>
00060     { operator double() { return 0.0; } };
00061 template<> struct additive_identity<int>
00062     { operator int() { return 0; } };
00063 template<> struct additive_identity<long int>
00064     { operator long int() { return 0L; } };
00065 
00066 template <class T>
00067 struct multiplicative_identity {};
00068 
00069 template<> struct multiplicative_identity<double>
00070     { operator double() { return 1.0; } };
00071 template<> struct multiplicative_identity<int>
00072     { operator int() { return 1; } };
00073 template<> struct multiplicative_identity<long int>
00074     { operator long int() { return 1L; }};
00075 
00076 
00077 
00078 //   O p e r a t o r   R e s u l t   T y p e   T e m p l a t e s
00079 
00080 
00081 template <class T, class U>
00082 struct balanced_type {};
00083 template <class T, class U>
00084 struct plus_type        { typedef typename balanced_type<T, U>::self self; };
00085 template <class T, class U>
00086 struct minus_type       { typedef typename plus_type<T, U>::self self; };
00087 template <class T, class U>
00088 struct times_type       { typedef typename balanced_type<T, U>::self self; };
00089 template <class T, class U>
00090 struct divides_type     { typedef typename times_type<T, U>::self self; };
00091 template <class T, class U>
00092 struct remainder_type   { typedef typename divides_type<T, U>::self self; };
00093 template <class T>
00094 struct negation_type    { typedef T self; };
00095 template <class T>
00096 struct inverse_type     { typedef void self; }; // invalid by default
00097 // more...
00098 
00099 
00100 
00101 //   S p e c i a l i s a t i o n   f o r   E l e m e n t a r y   T y p e s
00102 //
00103 //              -- Note:  Unsigned types are not supported.
00104 
00105 
00106 //  char [x] short [x] int [x] long
00107 
00108 template<> struct balanced_type<char, char>     { typedef char self; };
00109 
00110 template<> struct balanced_type<short, short>   { typedef short self; };
00111 template<> struct balanced_type<char, short>    { typedef short self; };
00112 template<> struct balanced_type<short, char>    { typedef short self; };
00113 
00114 template<> struct balanced_type<int, int>       { typedef int self; };
00115 template<> struct balanced_type<short, int>     { typedef int self; };
00116 template<> struct balanced_type<int, short>     { typedef int self; };
00117 template<> struct balanced_type<char, int>      { typedef int self; };
00118 template<> struct balanced_type<int, char>      { typedef int self; };
00119 
00120 template<> struct balanced_type<long, long>     { typedef long self; };
00121 template<> struct balanced_type<long, int>      { typedef long self; };
00122 template<> struct balanced_type<int, long>      { typedef long self; };
00123 template<> struct balanced_type<long, short>    { typedef long self; };
00124 template<> struct balanced_type<short, long>    { typedef long self; };
00125 template<> struct balanced_type<long, char>      { typedef long self; };
00126 template<> struct balanced_type<char, long>      { typedef long self; };
00127 
00128 
00129 //  float [x] double [x] long double
00130 
00131 template<> struct balanced_type<float, float>   { typedef float self; };
00132 
00133 template<> struct balanced_type<double, double> { typedef double self; };
00134 template<> struct balanced_type<double, float>  { typedef double self; };
00135 template<> struct balanced_type<float, double>  { typedef double self; };
00136 
00137 template<> struct balanced_type<long double, long double>
00138     { typedef long double self; };
00139 template<> struct balanced_type<long double, float>
00140     { typedef long double self; };
00141 template<> struct balanced_type<float, long double>
00142     { typedef long double self; };
00143 template<> struct balanced_type<long double, double>
00144     { typedef long double self; };
00145 template<> struct balanced_type<double, long double>
00146     { typedef long double self; };
00147 
00148 
00149 //  short, int, long [x] float, double, long double
00150 
00151 template<> struct balanced_type<float, short>   { typedef float self; };
00152 template<> struct balanced_type<short, float>   { typedef float self; };
00153 template<> struct balanced_type<float, int>     { typedef float self; };
00154 template<> struct balanced_type<int, float>     { typedef float self; };
00155 template<> struct balanced_type<float, long>    { typedef float self; };
00156 template<> struct balanced_type<long, float>    { typedef float self; };
00157 
00158 template<> struct balanced_type<double, short>  { typedef double self; };
00159 template<> struct balanced_type<short, double>  { typedef double self; };
00160 template<> struct balanced_type<double, int>    { typedef double self; };
00161 template<> struct balanced_type<int, double>    { typedef double self; };
00162 template<> struct balanced_type<double, long>   { typedef double self; };
00163 template<> struct balanced_type<long, double>   { typedef double self; };
00164 
00165 template<> struct balanced_type<long double, short>
00166     { typedef long double self; };
00167 template<> struct balanced_type<short, long double>
00168     { typedef long double self; };
00169 template<> struct balanced_type<long double, int>
00170     { typedef long double self; };
00171 template<> struct balanced_type<int, long double>
00172     { typedef long double self; };
00173 template<> struct balanced_type<long double, long>
00174     { typedef long double self; };
00175 template<> struct balanced_type<long, long double>
00176     { typedef long double self; };
00177 
00178 }}
00179 
00180 ///\endif
00181 
00182 #endif

Generated on Sat Sep 7 19:11:20 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.