1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
4
* Christian Schulte <schulte@gecode.org>
5
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
8
* Christian Schulte, 2002
9
* Vincent Barichard, 2012
12
* $Date: 2013-01-29 20:40:12 +0100 (Tue, 29 Jan 2013) $ by $Author: schulte $
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40
#include <gecode/float/arithmetic.hh>
41
#ifdef GECODE_HAS_MPFR
42
#include <gecode/float/transcendental.hh>
43
#include <gecode/float/trigonometric.hh>
49
abs(Home home, FloatVar x0, FloatVar x1) {
50
using namespace Float;
51
if (home.failed()) return;
52
GECODE_ES_FAIL((Arithmetic::Abs<FloatView,FloatView>::post(home,x0,x1)));
57
max(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
58
using namespace Float;
59
if (home.failed()) return;
60
GECODE_ES_FAIL((Arithmetic::Max<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
64
max(Home home, const FloatVarArgs& x, FloatVar y) {
65
using namespace Float;
67
throw TooFewArguments("Float::max");
68
if (home.failed()) return;
69
ViewArray<FloatView> xv(home,x);
70
GECODE_ES_FAIL(Arithmetic::NaryMax<FloatView>::post(home,xv,y));
75
min(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
76
using namespace Float;
77
if (home.failed()) return;
78
GECODE_ES_FAIL((Arithmetic::Min<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
82
min(Home home, const FloatVarArgs& x, FloatVar y) {
83
using namespace Float;
85
throw TooFewArguments("Float::min");
86
if (home.failed()) return;
87
ViewArray<MinusView> m(home,x.size());
88
for (int i=x.size(); i--; )
89
m[i] = MinusView(x[i]);
91
GECODE_ES_FAIL(Arithmetic::NaryMax<MinusView>::post(home,m,my));
96
mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
97
using namespace Float;
98
if (home.failed()) return;
99
GECODE_ES_FAIL((Arithmetic::Mult<FloatView>::post(home,x0,x1,x2)));
103
sqr(Home home, FloatVar x0, FloatVar x1) {
104
using namespace Float;
105
if (home.failed()) return;
106
GECODE_ES_FAIL((Arithmetic::Sqr<FloatView>::post(home,x0,x1)));
110
sqrt(Home home, FloatVar x0, FloatVar x1) {
111
using namespace Float;
112
if (home.failed()) return;
113
GECODE_ES_FAIL((Arithmetic::Sqrt<FloatView,FloatView>::post(home,x0,x1)));
117
pow(Home home, FloatVar x0, int n, FloatVar x1) {
118
using namespace Float;
120
throw OutOfLimits("nroot");
121
if (home.failed()) return;
122
GECODE_ES_FAIL((Arithmetic::Pow<FloatView,FloatView>::post(home,x0,x1,n)));
126
nroot(Home home, FloatVar x0, int n, FloatVar x1) {
127
using namespace Float;
129
throw OutOfLimits("nroot");
130
if (home.failed()) return;
131
GECODE_ES_FAIL((Arithmetic::NthRoot<FloatView,FloatView>::post(home,x0,x1,n)));
135
div(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
136
using namespace Float;
137
if (home.failed()) return;
139
(Arithmetic::Div<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
142
#ifdef GECODE_HAS_MPFR
144
exp(Home home, FloatVar x0, FloatVar x1) {
145
using namespace Float;
146
if (home.failed()) return;
147
GECODE_ES_FAIL((Transcendental::Exp<FloatView,FloatView>::post(home,x0,x1)));
151
log(Home home, FloatVar x0, FloatVar x1) {
152
using namespace Float;
153
if (home.failed()) return;
154
GECODE_ES_FAIL((Transcendental::Exp<FloatView,FloatView>
155
::post(home,x1,x0)));
159
log(Home home, FloatNum base, FloatVar x0, FloatVar x1) {
160
using namespace Float;
161
if (home.failed()) return;
162
GECODE_ES_FAIL((Transcendental::Pow<FloatView,FloatView>
163
::post(home,base,x1,x0)));
167
pow(Home home, FloatNum base, FloatVar x0, FloatVar x1) {
168
using namespace Float;
169
if (home.failed()) return;
170
GECODE_ES_FAIL((Transcendental::Pow<FloatView,FloatView>
171
::post(home,base,x0,x1)));
175
asin(Home home, FloatVar x0, FloatVar x1) {
176
using namespace Float;
177
if (home.failed()) return;
178
GECODE_ES_FAIL((Trigonometric::ASin<FloatView,FloatView>::post(home,x0,x1)));
182
sin(Home home, FloatVar x0, FloatVar x1) {
183
using namespace Float;
184
if (home.failed()) return;
185
GECODE_ES_FAIL((Trigonometric::Sin<FloatView,FloatView>::post(home,x0,x1)));
189
acos(Home home, FloatVar x0, FloatVar x1) {
190
using namespace Float;
191
if (home.failed()) return;
192
GECODE_ES_FAIL((Trigonometric::ACos<FloatView,FloatView>::post(home,x0,x1)));
196
cos(Home home, FloatVar x0, FloatVar x1) {
197
using namespace Float;
198
if (home.failed()) return;
199
GECODE_ES_FAIL((Trigonometric::Cos<FloatView,FloatView>::post(home,x0,x1)));
203
atan(Home home, FloatVar x0, FloatVar x1) {
204
using namespace Float;
205
if (home.failed()) return;
206
GECODE_ES_FAIL((Trigonometric::ATan<FloatView,FloatView>::post(home,x0,x1)));
210
tan(Home home, FloatVar x0, FloatVar x1) {
211
using namespace Float;
212
if (home.failed()) return;
213
GECODE_ES_FAIL((Trigonometric::Tan<FloatView,FloatView>::post(home,x0,x1)));
218
channel(Home home, FloatVar x0, IntVar x1) {
219
using namespace Float;
221
if (home.failed()) return;
222
GECODE_ES_FAIL((Arithmetic::Channel<FloatView,IntView>::post(home,x0,x1)));
226
channel(Home home, IntVar x0, FloatVar x1) {
227
using namespace Float;
229
if (home.failed()) return;
230
GECODE_ES_FAIL((Arithmetic::Channel<FloatView,IntView>::post(home,x1,x0)));
235
// STATISTICS: float-post