• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/export/development/ViennaMath/viennamath/compiletime/operations/ct_constant.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_COMPILETIME_OPERATIONS_CT_CONSTANT_HPP
00002 #define VIENNAMATH_COMPILETIME_OPERATIONS_CT_CONSTANT_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2012, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008                              -----------------
00009                ViennaMath - Symbolic and Numerical Math in C++
00010                              -----------------
00011 
00012    Author:     Karl Rupp                          rupp@iue.tuwien.ac.at
00013 
00014    License:    MIT (X11), see file LICENSE in the ViennaMath base directory
00015 ======================================================================= */
00016 
00017 
00018 
00019 
00020 #include <ostream>
00021 #include "viennamath/forwards.h"
00022 #include "viennamath/compiletime/ct_constant.hpp"
00023 
00028 namespace viennamath
00029 {
00030       
00032   
00033   //operator+
00034 
00036   template <long value, typename ScalarType, typename RHS>
00037   ct_binary_expr<rt_constant< typename promote_traits<long, op_plus<default_numeric_type>, ScalarType>::result_type >,
00038                  op_plus<default_numeric_type>,
00039                  RHS >
00040   operator+(ct_constant<value> const & lhs, 
00041             ct_binary_expr<rt_constant<ScalarType>, op_plus<default_numeric_type>, RHS> const & other)
00042   {
00043     typedef rt_constant< typename promote_traits<long, op_plus<default_numeric_type>, ScalarType>::result_type >   result_constant;
00044     return ct_binary_expr<result_constant,
00045                           op_plus<default_numeric_type>,
00046                           RHS >(result_constant(value + other.lhs()), other.rhs());
00047   }
00048   
00050   template <long value, long value2, typename RHS>
00051   ct_binary_expr<ct_constant<value + value2>,
00052                  op_plus<default_numeric_type>,
00053                  RHS >
00054   operator+(ct_constant<value> const & lhs, 
00055             ct_binary_expr<ct_constant<value2>, op_plus<default_numeric_type>, RHS> const & other)
00056   {
00057     return ct_binary_expr<ct_constant<value + value2>,
00058                           op_plus<default_numeric_type>,
00059                           RHS >(ct_constant<value + value2>(), other.rhs());
00060   }
00061   
00063   template <long value, typename ScalarType, typename RHS>
00064   ct_binary_expr<rt_constant< typename promote_traits<long, op_plus<default_numeric_type>, ScalarType>::result_type >,
00065                  op_minus<default_numeric_type>,
00066                  RHS >
00067   operator+(ct_constant<value> const & lhs, 
00068             ct_binary_expr<rt_constant<ScalarType>, op_minus<default_numeric_type>, RHS> const & other)
00069   {
00070     typedef rt_constant< typename promote_traits<long, op_plus<default_numeric_type>, ScalarType>::result_type >   result_constant;
00071     return ct_binary_expr<result_constant,
00072                           op_minus<default_numeric_type>,
00073                           RHS >(result_constant(value + other.lhs()), other.rhs());
00074   }
00075   
00077   template <long value, long value2, typename RHS>
00078   ct_binary_expr<ct_constant<value + value2>,
00079                  op_minus<default_numeric_type>,
00080                  RHS >
00081   operator+(ct_constant<value> const & lhs, 
00082             ct_binary_expr<ct_constant<value2>, op_minus<default_numeric_type>, RHS> const & other)
00083   {
00084     return ct_binary_expr<ct_constant<value + value2>,
00085                           op_minus<default_numeric_type>,
00086                           RHS >(ct_constant<value + value2>(), other.rhs());
00087   }
00088   
00090   template <long value, long other_value>
00091   ct_constant<value + other_value>
00092   operator+(ct_constant<value> const & lhs, 
00093             ct_constant<other_value> const & other)
00094   {
00095     return ct_constant<value + other_value>();
00096   }
00097 
00098 
00099   //operator-
00100   
00102   template <long value, typename ScalarType, typename RHS>
00103   ct_binary_expr<rt_constant< typename promote_traits<long, op_minus<default_numeric_type>, ScalarType>::result_type >,
00104                  op_minus<default_numeric_type>,
00105                  RHS >
00106   operator-(ct_constant<value> const & lhs, 
00107             ct_binary_expr<rt_constant<ScalarType>, op_plus<default_numeric_type>, RHS> const & other)
00108   {
00109     typedef rt_constant< typename promote_traits<long, op_minus<default_numeric_type>, ScalarType>::result_type >   result_constant;
00110     return ct_binary_expr<result_constant,
00111                           op_minus<default_numeric_type>,
00112                           RHS >(result_constant(value - other.lhs()), other.rhs());
00113   }
00114   
00116   template <long value, long value2, typename RHS>
00117   ct_binary_expr<ct_constant<value - value2>,
00118                  op_minus<default_numeric_type>,
00119                  RHS >
00120   operator-(ct_constant<value> const & lhs, 
00121             ct_binary_expr<ct_constant<value2>, op_plus<default_numeric_type>, RHS> const & other)
00122   {
00123     return ct_binary_expr<ct_constant<value - value2>,
00124                           op_minus<default_numeric_type>,
00125                           RHS >(ct_constant<value - value2>(), other.rhs());
00126   }
00127   
00129   template <long value, typename ScalarType, typename RHS>
00130   ct_binary_expr<rt_constant< typename promote_traits<long, op_minus<default_numeric_type>, ScalarType>::result_type >,
00131                  op_plus<default_numeric_type>,
00132                  RHS >
00133   operator-(ct_constant<value> const & lhs, 
00134             ct_binary_expr<rt_constant<ScalarType>, op_minus<default_numeric_type>, RHS> const & other)
00135   {
00136     typedef rt_constant< typename promote_traits<long, op_minus<default_numeric_type>, ScalarType>::result_type >   result_constant;
00137     return ct_binary_expr<result_constant,
00138                           op_plus<default_numeric_type>,
00139                           RHS >(result_constant(value - other.lhs()), other.rhs());
00140   }
00141   
00143   template <long value, long value2, typename RHS>
00144   ct_binary_expr<ct_constant<value - value2>,
00145                  op_plus<default_numeric_type>,
00146                  RHS >
00147   operator-(ct_constant<value> const & lhs, 
00148             ct_binary_expr<ct_constant<value2>, op_minus<default_numeric_type>, RHS> const & other)
00149   {
00150     return ct_binary_expr<ct_constant<value - value2>,
00151                           op_plus<default_numeric_type>,
00152                           RHS >(ct_constant<value - value2>(), other.rhs());
00153   }
00154   
00156   template <long value, long other_value>
00157   ct_constant<value - other_value>
00158   operator-(ct_constant<value> const & lhs, 
00159             ct_constant<other_value> const & other)
00160   {
00161     return ct_constant<value - other_value>();
00162   }
00163 
00164 
00165   //operator*
00166 
00168   template <long value, long other_value>
00169   ct_constant<value * other_value>
00170   operator*(ct_constant<value> const & lhs, 
00171             ct_constant<other_value> const & other)
00172   {
00173     return ct_constant<value * other_value>();
00174   }
00175 
00176 
00177   //operator/
00178   
00179   // (none so far)
00180   
00181 }
00182 
00183 #endif

Generated on Wed Feb 29 2012 21:50:43 for ViennaMath by  doxygen 1.7.1