main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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: 2016-08-11 16:02:23 +0200 (Thu, 11 Aug 2016) $ by $Author: schulte $
11
* $Revision: 15143 $
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
) {
42
RoundingBase::init();
43
}
44
forceinline
45
Rounding::~Rounding
(
void
) {}
46
47
forceinline
FloatNum
48
Rounding::median
(
FloatNum
x
,
FloatNum
y
) {
49
return
RoundingBase::median(
x
,
y
);
50
}
51
52
#define GECODE_ROUND_OP(name) \
53
forceinline FloatNum \
54
Rounding::name##_down(FloatNum x, FloatNum y) { \
55
return RoundingBase::name##_down(x,y); \
56
} \
57
forceinline FloatNum \
58
Rounding::name##_up(FloatNum x, FloatNum y) { \
59
return RoundingBase::name##_up(x,y); \
60
}
61
62
GECODE_ROUND_OP
(add)
63
GECODE_ROUND_OP
(sub)
64
GECODE_ROUND_OP
(mul)
65
GECODE_ROUND_OP
(
div
)
66
67
#undef GECODE_ROUND_OP
68
69
#define GECODE_ROUND_FUN(name) \
70
forceinline FloatNum \
71
Rounding::name##_down(FloatNum x) { \
72
return RoundingBase::name##_down(x); \
73
} \
74
forceinline FloatNum \
75
Rounding::name##_up(FloatNum x) { \
76
return RoundingBase::name##_up(x); \
77
}
78
79
GECODE_ROUND_FUN
(
sqrt
)
80
81
#if defined(_M_X64) || defined(_M_IA64)
82
83
// Workaround as MSVC on x64 does not have a rint function
84
forceinline
FloatNum
85
Rounding::int_down
(
FloatNum
x
) {
86
return
floor(
x
);
87
}
88
forceinline
FloatNum
89
Rounding::int_up
(
FloatNum
x
) {
90
return
ceil(
x
);
91
}
92
93
#else
94
95
GECODE_ROUND_FUN
(
int
)
96
97
#endif
98
99
#undef GECODE_ROUND_FUN
100
101
}}
102
103
// STATISTICS: float-var
104
Gecode::Float::Rounding::int_down
FloatNum int_down(FloatNum x)
Return next downward-rounded integer of x (domain: )
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Float::Rounding::int_up
FloatNum int_up(FloatNum x)
Return next upward-rounded integer of x (domain: )
Gecode::Float::Rounding::~Rounding
~Rounding(void)
Destructor (restores previous rounding mode)
Definition:
rounding.hpp:45
Gecode::Float::Rounding::Rounding
Rounding(void)
Default constructor (configures full rounding mode)
Definition:
rounding.hpp:41
Gecode::div
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:131
Gecode
Gecode toplevel namespace
GECODE_ROUND_FUN
#define GECODE_ROUND_FUN(name)
Definition:
rounding.hpp:69
Gecode::sqrt
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
arithmetic.cpp:106
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:110
GECODE_ROUND_OP
#define GECODE_ROUND_OP(name)
Definition:
rounding.hpp:52
Gecode::Float::Rounding::median
FloatNum median(FloatNum x, FloatNum y)
Return median of x and y (domain: )
Definition:
rounding.hpp:48