main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:25 for Gecode by
doxygen
1.8.4
gecode
float
arithmetic.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6
*
7
* Copyright:
8
* Christian Schulte, 2002
9
* Vincent Barichard, 2012
10
*
11
* Last modified:
12
* $Date: 2013-01-29 20:40:12 +0100 (Tue, 29 Jan 2013) $ by $Author: schulte $
13
* $Revision: 13246 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
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:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
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.
37
*
38
*/
39
40
#include <
gecode/float/arithmetic.hh
>
41
#ifdef GECODE_HAS_MPFR
42
#include <
gecode/float/transcendental.hh
>
43
#include <
gecode/float/trigonometric.hh
>
44
#endif
45
46
namespace
Gecode {
47
48
void
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)));
53
}
54
55
56
void
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)));
61
}
62
63
void
64
max
(
Home
home,
const
FloatVarArgs
&
x
,
FloatVar
y) {
65
using namespace
Float;
66
if
(x.
size
() == 0)
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));
71
}
72
73
74
void
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)));
79
}
80
81
void
82
min
(
Home
home,
const
FloatVarArgs
&
x
,
FloatVar
y) {
83
using namespace
Float;
84
if
(x.
size
() == 0)
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
]);
90
MinusView
my(y);
91
GECODE_ES_FAIL
(
Arithmetic::NaryMax<MinusView>::post
(home,m,my));
92
}
93
94
95
void
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)));
100
}
101
102
void
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)));
107
}
108
109
void
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)));
114
}
115
116
void
117
pow
(
Home
home,
FloatVar
x0,
int
n
,
FloatVar
x1) {
118
using namespace
Float;
119
if
(n < 0)
120
throw
OutOfLimits
(
"nroot"
);
121
if
(home.
failed
())
return
;
122
GECODE_ES_FAIL
((
Arithmetic::Pow<FloatView,FloatView>::post
(home,x0,x1,n)));
123
}
124
125
void
126
nroot
(
Home
home,
FloatVar
x0,
int
n
,
FloatVar
x1) {
127
using namespace
Float;
128
if
(n < 0)
129
throw
OutOfLimits
(
"nroot"
);
130
if
(home.
failed
())
return
;
131
GECODE_ES_FAIL
((
Arithmetic::NthRoot<FloatView,FloatView>::post
(home,x0,x1,n)));
132
}
133
134
void
135
div
(
Home
home,
FloatVar
x0,
FloatVar
x1,
FloatVar
x2) {
136
using namespace
Float;
137
if
(home.
failed
())
return
;
138
GECODE_ES_FAIL
(
139
(
Arithmetic::Div<FloatView,FloatView,FloatView>::post
(home,x0,x1,x2)));
140
}
141
142
#ifdef GECODE_HAS_MPFR
143
void
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)));
148
}
149
150
void
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)));
156
}
157
158
void
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)));
164
}
165
166
void
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)));
172
}
173
174
void
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)));
179
}
180
181
void
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)));
186
}
187
188
void
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)));
193
}
194
195
void
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)));
200
}
201
202
void
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)));
207
}
208
209
void
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)));
214
}
215
#endif
216
217
void
218
channel
(
Home
home,
FloatVar
x0,
IntVar
x1) {
219
using namespace
Float;
220
using namespace
Int;
221
if
(home.
failed
())
return
;
222
GECODE_ES_FAIL
((
Arithmetic::Channel<FloatView,IntView>::post
(home,x0,x1)));
223
}
224
225
void
226
channel
(
Home
home,
IntVar
x0,
FloatVar
x1) {
227
using namespace
Float;
228
using namespace
Int;
229
if
(home.
failed
())
return
;
230
GECODE_ES_FAIL
((
Arithmetic::Channel<FloatView,IntView>::post
(home,x1,x0)));
231
}
232
233
}
234
235
// STATISTICS: float-post