main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:26 for Gecode by
doxygen
1.8.4
gecode
float
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
40
forceinline
41
Rounding::Rounding
(
void
) { Base::init(); }
42
forceinline
43
Rounding::~Rounding
(
void
) {}
44
45
forceinline
FloatNum
46
Rounding::median
(
FloatNum
x
,
FloatNum
y) {
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)
63
GECODE_ROUND_OP
(
div
)
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
77
GECODE_ROUND_FUN
(
sqrt
)
78
79
#if defined(_M_X64) || defined(_M_IA64)
80
81
// Workaround as MSVC on x64 does not have a rint function
82
forceinline
FloatNum
83
Rounding::int_down
(
FloatNum
x
) {
84
return
floor(x);
85
}
86
forceinline
FloatNum
87
Rounding::int_up
(
FloatNum
x
) {
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