00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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