Skip to content

Commit 70defaa

Browse files
author
Christian Schulte
committed
Floats coming soon
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@12631 e85b7adc-8362-4630-8c63-7469d557c915
1 parent 561102a commit 70defaa

51 files changed

Lines changed: 11234 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gecode/float.hh

Lines changed: 652 additions & 0 deletions
Large diffs are not rendered by default.

gecode/float/arithmetic.cpp

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
/*
3+
* Main authors:
4+
*
5+
* Copyright:
6+
*
7+
* Last modified:
8+
*
9+
* This file is part of Gecode, the generic constraint
10+
* development environment:
11+
* http://www.gecode.org
12+
*
13+
* Permission is hereby granted, free of charge, to any person obtaining
14+
* a copy of this software and associated documentation files (the
15+
* "Software"), to deal in the Software without restriction, including
16+
* without limitation the rights to use, copy, modify, merge, publish,
17+
* distribute, sublicense, and/or sell copies of the Software, and to
18+
* permit persons to whom the Software is furnished to do so, subject to
19+
* the following conditions:
20+
*
21+
* The above copyright notice and this permission notice shall be
22+
* included in all copies or substantial portions of the Software.
23+
*
24+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31+
*
32+
*/
33+
34+
#include <gecode/float/arithmetic.hh>
35+
#ifdef GECODE_HAS_MPFR
36+
#include <gecode/float/transcendental.hh>
37+
#include <gecode/float/trigonometric.hh>
38+
#endif
39+
40+
namespace Gecode {
41+
42+
using namespace Float;
43+
44+
void
45+
abs(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
46+
if (home.failed()) return;
47+
GECODE_ES_FAIL((Arithmetic::Abs<FloatView,FloatView>::post(home,x0,x1)));
48+
}
49+
50+
51+
void
52+
max(Home home, FloatVar x0, FloatVar x1, FloatVar x2,
53+
FloatConLevel ) {
54+
if (home.failed()) return;
55+
GECODE_ES_FAIL((Arithmetic::Max<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
56+
}
57+
58+
void
59+
max(Home home, const FloatVarArgs& x, FloatVar y,
60+
FloatConLevel ) {
61+
if (x.size() == 0)
62+
throw TooFewArguments("Float::max");
63+
if (home.failed()) return;
64+
ViewArray<FloatView> xv(home,x);
65+
GECODE_ES_FAIL(Arithmetic::NaryMax<FloatView>::post(home,xv,y));
66+
}
67+
68+
69+
void
70+
min(Home home, FloatVar x0, FloatVar x1, FloatVar x2,
71+
FloatConLevel ) {
72+
if (home.failed()) return;
73+
GECODE_ES_FAIL((Arithmetic::Min<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
74+
}
75+
76+
void
77+
min(Home home, const FloatVarArgs& x, FloatVar y,
78+
FloatConLevel ) {
79+
if (x.size() == 0)
80+
throw TooFewArguments("Float::min");
81+
if (home.failed()) return;
82+
ViewArray<MinusView> m(home,x.size());
83+
for (int i=x.size(); i--; )
84+
m[i] = MinusView(x[i]);
85+
MinusView my(y);
86+
GECODE_ES_FAIL(Arithmetic::NaryMax<MinusView>::post(home,m,my));
87+
}
88+
89+
90+
void
91+
mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2,
92+
FloatConLevel) {
93+
if (home.failed()) return;
94+
GECODE_ES_FAIL((Arithmetic::Mult<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
95+
}
96+
97+
void
98+
sqr(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
99+
if (home.failed()) return;
100+
GECODE_ES_FAIL((Arithmetic::Square<FloatView,FloatView>::post(home,x0,x1)));
101+
}
102+
103+
void
104+
sqrt(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
105+
if (home.failed()) return;
106+
GECODE_ES_FAIL((Arithmetic::Sqrt<FloatView,FloatView>::post(home,x0,x1)));
107+
}
108+
109+
void
110+
pow(Home home, FloatVar x0, FloatVar x1, int exp, FloatConLevel ) {
111+
if (home.failed()) return;
112+
GECODE_ES_FAIL((Arithmetic::Pow<FloatView,FloatView>::post(home,x0,x1,exp)));
113+
}
114+
115+
void
116+
nroot(Home home, FloatVar x0, FloatVar x1, int exp, FloatConLevel ) {
117+
if (home.failed()) return;
118+
GECODE_ES_FAIL((Arithmetic::NthRoot<FloatView,FloatView>::post(home,x0,x1,exp)));
119+
}
120+
121+
void
122+
div(Home home, FloatVar x0, FloatVar x1, FloatVar x2,
123+
FloatConLevel) {
124+
if (home.failed()) return;
125+
GECODE_ES_FAIL(
126+
(Arithmetic::Div<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
127+
}
128+
129+
#ifdef GECODE_HAS_MPFR
130+
void
131+
exp(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
132+
if (home.failed()) return;
133+
GECODE_ES_FAIL((Transcendental::Exp<FloatView,FloatView>::post(home,x0,x1)));
134+
}
135+
136+
void
137+
log(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
138+
if (home.failed()) return;
139+
GECODE_ES_FAIL((Transcendental::Log<FloatView,FloatView>::post(home,x0,x1)));
140+
}
141+
142+
void
143+
asin(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
144+
if (home.failed()) return;
145+
GECODE_ES_FAIL((Trigonometric::ASin<FloatView,FloatView>::post(home,x0,x1)));
146+
}
147+
148+
void
149+
sin(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
150+
if (home.failed()) return;
151+
GECODE_ES_FAIL((Trigonometric::Sin<FloatView,FloatView>::post(home,x0,x1)));
152+
}
153+
154+
void
155+
acos(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
156+
if (home.failed()) return;
157+
GECODE_ES_FAIL((Trigonometric::ACos<FloatView,FloatView>::post(home,x0,x1)));
158+
}
159+
160+
void
161+
cos(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
162+
if (home.failed()) return;
163+
GECODE_ES_FAIL((Trigonometric::Cos<FloatView,FloatView>::post(home,x0,x1)));
164+
}
165+
166+
void
167+
atan(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
168+
if (home.failed()) return;
169+
GECODE_ES_FAIL((Trigonometric::ATan<FloatView,FloatView>::post(home,x0,x1)));
170+
}
171+
172+
void
173+
tan(Home home, FloatVar x0, FloatVar x1, FloatConLevel ) {
174+
if (home.failed()) return;
175+
GECODE_ES_FAIL((Trigonometric::Tan<FloatView,FloatView>::post(home,x0,x1)));
176+
}
177+
#endif
178+
179+
void
180+
channel(Home home, FloatVar x0, IntVar x1, FloatConLevel) {
181+
using namespace Int;
182+
if (home.failed()) return;
183+
GECODE_ES_FAIL((Arithmetic::Channel<FloatView,IntView>::post(home,x0,x1)));
184+
}
185+
}
186+
187+
// STATISTICS: float-post

0 commit comments

Comments
 (0)