Generated on Sat Feb 7 2015 02:01:17 for Gecode by doxygen 1.8.9.1
rounding.hpp
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  *
6  * Copyright:
7  * Christian Schulte, 2012
8  *
9  * Last modified:
10  * $Date: 2013-02-13 09:12:37 +0100 (Wed, 13 Feb 2013) $ by $Author: vbarichard $
11  * $Revision: 13285 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Float {
39 
41  Rounding::Rounding(void) { Base::init(); }
44 
47  return Base::median(x,y);
48  }
49 
50 #define GECODE_ROUND_OP(name) \
51  forceinline FloatNum \
52  Rounding::name##_down(FloatNum x, FloatNum y) { \
53  return Base::name##_down(x,y); \
54  } \
55  forceinline FloatNum \
56  Rounding::name##_up(FloatNum x, FloatNum y) { \
57  return Base::name##_up(x,y); \
58  }
59 
60  GECODE_ROUND_OP(add)
61  GECODE_ROUND_OP(sub)
62  GECODE_ROUND_OP(mul)
64 
65 #undef GECODE_ROUND_OP
66 
67 #define GECODE_ROUND_FUN(name) \
68  forceinline FloatNum \
69  Rounding::name##_down(FloatNum x) { \
70  return Base::name##_down(x); \
71  } \
72  forceinline FloatNum \
73  Rounding::name##_up(FloatNum x) { \
74  return Base::name##_up(x); \
75  }
76 
78 
79 #if defined(_M_X64) || defined(_M_IA64)
80 
81  // Workaround as MSVC on x64 does not have a rint function
84  return floor(x);
85  }
88  return ceil(x);
89  }
90 
91 #else
92 
93  GECODE_ROUND_FUN(int)
94 
95 #endif
96 
97 #undef GECODE_ROUND_FUN
98 
99 }}
100 
101 // STATISTICS: float-var
102 
FloatNum int_down(FloatNum x)
Return next downward-rounded integer of x (domain: )
#define GECODE_ROUND_FUN(name)
Definition: rounding.hpp:67
#define GECODE_ROUND_OP(name)
Definition: rounding.hpp:50
FloatNum int_up(FloatNum x)
Return next upward-rounded integer of x (domain: )
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:110
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:135
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Rounding(void)
Default constructor (configures full rounding mode)
Definition: rounding.hpp:41
#define forceinline
Definition: config.hpp:132
Gecode toplevel namespace
double FloatNum
Floating point number base type.
Definition: float.hh:108
~Rounding(void)
Destructor (restores previous rounding mode)
Definition: rounding.hpp:43
FloatNum median(FloatNum x, FloatNum y)
Return median of x and y (domain: )
Definition: rounding.hpp:46