Generated on Fri Mar 20 15:55:56 2015 for Gecode by doxygen 1.6.3

arithmetic.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Vincent Barichard, 2012
00010  *
00011  *  Last modified:
00012  *     $Date: 2013-01-29 20:40:12 +0100 (Tue, 29 Jan 2013) $ by $Author: schulte $
00013  *     $Revision: 13246 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include <gecode/float/arithmetic.hh>
00041 #ifdef GECODE_HAS_MPFR
00042 #include <gecode/float/transcendental.hh>
00043 #include <gecode/float/trigonometric.hh>
00044 #endif
00045 
00046 namespace Gecode {
00047 
00048   void
00049   abs(Home home, FloatVar x0, FloatVar x1) {
00050     using namespace Float;
00051     if (home.failed()) return;
00052     GECODE_ES_FAIL((Arithmetic::Abs<FloatView,FloatView>::post(home,x0,x1)));
00053   }
00054 
00055 
00056   void
00057   max(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
00058     using namespace Float;
00059     if (home.failed()) return;
00060     GECODE_ES_FAIL((Arithmetic::Max<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
00061   }
00062 
00063   void
00064   max(Home home, const FloatVarArgs& x, FloatVar y) {
00065     using namespace Float;
00066     if (x.size() == 0)
00067       throw TooFewArguments("Float::max");
00068     if (home.failed()) return;
00069     ViewArray<FloatView> xv(home,x);
00070     GECODE_ES_FAIL(Arithmetic::NaryMax<FloatView>::post(home,xv,y));
00071   }
00072 
00073 
00074   void
00075   min(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
00076     using namespace Float;
00077     if (home.failed()) return;
00078     GECODE_ES_FAIL((Arithmetic::Min<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
00079   }
00080 
00081   void
00082   min(Home home, const FloatVarArgs& x, FloatVar y) {
00083     using namespace Float;
00084     if (x.size() == 0)
00085       throw TooFewArguments("Float::min");
00086     if (home.failed()) return;
00087     ViewArray<MinusView> m(home,x.size());
00088     for (int i=x.size(); i--; )
00089       m[i] = MinusView(x[i]);
00090     MinusView my(y);
00091     GECODE_ES_FAIL(Arithmetic::NaryMax<MinusView>::post(home,m,my));
00092   }
00093 
00094 
00095   void
00096   mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
00097     using namespace Float;
00098     if (home.failed()) return;
00099     GECODE_ES_FAIL((Arithmetic::Mult<FloatView>::post(home,x0,x1,x2)));
00100   }
00101 
00102   void
00103   sqr(Home home, FloatVar x0, FloatVar x1) {
00104     using namespace Float;
00105     if (home.failed()) return;
00106     GECODE_ES_FAIL((Arithmetic::Sqr<FloatView>::post(home,x0,x1)));
00107   }
00108 
00109   void
00110   sqrt(Home home, FloatVar x0, FloatVar x1) {
00111     using namespace Float;
00112     if (home.failed()) return;
00113     GECODE_ES_FAIL((Arithmetic::Sqrt<FloatView,FloatView>::post(home,x0,x1)));
00114   }
00115 
00116   void
00117   pow(Home home, FloatVar x0, int n, FloatVar x1) {
00118     using namespace Float;
00119     if (n < 0)
00120       throw OutOfLimits("nroot");
00121     if (home.failed()) return;
00122     GECODE_ES_FAIL((Arithmetic::Pow<FloatView,FloatView>::post(home,x0,x1,n)));
00123   }
00124 
00125   void
00126   nroot(Home home, FloatVar x0, int n, FloatVar x1) {
00127     using namespace Float;
00128     if (n < 0)
00129       throw OutOfLimits("nroot");
00130     if (home.failed()) return;
00131     GECODE_ES_FAIL((Arithmetic::NthRoot<FloatView,FloatView>::post(home,x0,x1,n)));
00132   }
00133 
00134   void
00135   div(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
00136     using namespace Float;
00137     if (home.failed()) return;
00138     GECODE_ES_FAIL(
00139       (Arithmetic::Div<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
00140   }
00141 
00142 #ifdef GECODE_HAS_MPFR
00143   void
00144   exp(Home home, FloatVar x0, FloatVar x1) {
00145     using namespace Float;
00146     if (home.failed()) return;
00147     GECODE_ES_FAIL((Transcendental::Exp<FloatView,FloatView>::post(home,x0,x1)));
00148   }
00149 
00150   void
00151   log(Home home, FloatVar x0, FloatVar x1) {
00152     using namespace Float;
00153     if (home.failed()) return;
00154     GECODE_ES_FAIL((Transcendental::Exp<FloatView,FloatView>
00155       ::post(home,x1,x0)));
00156   }
00157 
00158   void
00159   log(Home home, FloatNum base, FloatVar x0, FloatVar x1) {
00160     using namespace Float;
00161     if (home.failed()) return;
00162     GECODE_ES_FAIL((Transcendental::Pow<FloatView,FloatView>
00163       ::post(home,base,x1,x0)));
00164   }
00165 
00166   void
00167   pow(Home home, FloatNum base, FloatVar x0, FloatVar x1) {
00168     using namespace Float;
00169     if (home.failed()) return;
00170     GECODE_ES_FAIL((Transcendental::Pow<FloatView,FloatView>
00171       ::post(home,base,x0,x1)));
00172   }
00173 
00174   void
00175   asin(Home home, FloatVar x0, FloatVar x1) {
00176     using namespace Float;
00177     if (home.failed()) return;
00178     GECODE_ES_FAIL((Trigonometric::ASin<FloatView,FloatView>::post(home,x0,x1)));
00179   }
00180 
00181   void
00182   sin(Home home, FloatVar x0, FloatVar x1) {
00183     using namespace Float;
00184     if (home.failed()) return;
00185     GECODE_ES_FAIL((Trigonometric::Sin<FloatView,FloatView>::post(home,x0,x1)));
00186   }
00187 
00188   void
00189   acos(Home home, FloatVar x0, FloatVar x1) {
00190     using namespace Float;
00191     if (home.failed()) return;
00192     GECODE_ES_FAIL((Trigonometric::ACos<FloatView,FloatView>::post(home,x0,x1)));
00193   }
00194 
00195   void
00196   cos(Home home, FloatVar x0, FloatVar x1) {
00197     using namespace Float;
00198     if (home.failed()) return;
00199     GECODE_ES_FAIL((Trigonometric::Cos<FloatView,FloatView>::post(home,x0,x1)));
00200   }
00201 
00202   void
00203   atan(Home home, FloatVar x0, FloatVar x1) {
00204     using namespace Float;
00205     if (home.failed()) return;
00206     GECODE_ES_FAIL((Trigonometric::ATan<FloatView,FloatView>::post(home,x0,x1)));
00207   }
00208 
00209   void
00210   tan(Home home, FloatVar x0, FloatVar x1) {
00211     using namespace Float;
00212     if (home.failed()) return;
00213     GECODE_ES_FAIL((Trigonometric::Tan<FloatView,FloatView>::post(home,x0,x1)));
00214   }
00215 #endif
00216 
00217   void
00218   channel(Home home, FloatVar x0, IntVar x1) {
00219     using namespace Float;
00220     using namespace Int;
00221     if (home.failed()) return;
00222     GECODE_ES_FAIL((Arithmetic::Channel<FloatView,IntView>::post(home,x0,x1)));
00223   }
00224 
00225   void
00226   channel(Home home, IntVar x0, FloatVar x1) {
00227     using namespace Float;
00228     using namespace Int;
00229     if (home.failed()) return;
00230     GECODE_ES_FAIL((Arithmetic::Channel<FloatView,IntView>::post(home,x1,x0)));
00231   }
00232 
00233 }
00234 
00235 // STATISTICS: float-post