LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fast_complex.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
17 #ifndef FAST_COMPLEX_HPP
18 #define FAST_COMPLEX_HPP
19 //helper class to eliminate operations
20 template<class T>
21 struct imag_unit{};
22 template<class T>
23 struct imag_val{
24  T val;
25 };
26 //Maybe get faster complex operations by using expression templates for a complex class
27 //This may or may not help, depending on how good compilers are at removing temporary objects
28 //maybe looking at asm generated for simpler code may help
29 template<class T>
30 struct fast_comp{
31  T rval;
32  T ival;
33  public:
34  inline fast_comp(){}
35  inline fast_comp(const T& r):rval(r){}
36  inline fast_comp(const T& r, const T& i):rval(r), ival(i){}
37  inline fast_comp(const fast_comp<T>& a):rval(a.rval), ival(a.ival){}
39  return fast_comp<T>(rval+a.rval, ival+a.ival);
40  }
42  return fast_comp<T>(rval-a.rval, ival-a.ival);
43  }
44  inline fast_comp operator *(const fast_comp<T>& a){
45  }
46 };
47 #endif