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.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
*
9
* Copyright:
10
* Christian Schulte, 2012
11
* Vincent Barichard, 2012
12
*
13
* Last modified:
14
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
15
* $Revision: 14967 $
16
*
17
* This file is part of Gecode, the generic constraint
18
* development environment:
19
* http://www.gecode.org
20
*
21
* Permission is hereby granted, free of charge, to any person obtaining
22
* a copy of this software and associated documentation files (the
23
* "Software"), to deal in the Software without restriction, including
24
* without limitation the rights to use, copy, modify, merge, publish,
25
* distribute, sublicense, and/or sell copies of the Software, and to
26
* permit persons to whom the Software is furnished to do so, subject to
27
* the following conditions:
28
*
29
* The above copyright notice and this permission notice shall be
30
* included in all copies or substantial portions of the Software.
31
*
32
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
*
40
*/
41
42
#include <
gecode/float.hh
>
43
44
#ifdef GECODE_HAS_MPFR
45
46
#include <gmp.h>
47
#include <mpfr.h>
48
49
namespace
Gecode
{
namespace
Float {
50
52
typedef
int
mpfr_func
(mpfr_t,
const
__mpfr_struct*, mp_rnd_t);
53
55
forceinline
double
56
invoke_mpfr
(
FloatNum
x
,
mpfr_func
f
, mp_rnd_t
r
) {
57
mpfr_t xx;
58
mpfr_init_set_d(xx,
x
, GMP_RNDN);
59
f
(xx, xx,
r
);
60
FloatNum
res = mpfr_get_d(xx,
r
);
61
mpfr_clear(xx);
62
return
res;
63
}
64
66
#define GECODE_GENR_FUNC(name) \
67
FloatNum Rounding::name##_down(FloatNum x) { \
68
return invoke_mpfr(x, mpfr_##name, GMP_RNDD); \
69
} \
70
FloatNum Rounding::name##_up(FloatNum x) { \
71
return invoke_mpfr(x, mpfr_##name, GMP_RNDU); \
72
}
73
GECODE_GENR_FUNC
(
exp
)
74
GECODE_GENR_FUNC
(
log
)
75
GECODE_GENR_FUNC
(
sin
)
76
GECODE_GENR_FUNC
(
cos
)
77
GECODE_GENR_FUNC
(
tan
)
78
GECODE_GENR_FUNC
(
asin
)
79
GECODE_GENR_FUNC
(
acos
)
80
GECODE_GENR_FUNC
(
atan
)
81
GECODE_GENR_FUNC
(
sinh
)
82
GECODE_GENR_FUNC
(
cosh
)
83
GECODE_GENR_FUNC
(
tanh
)
84
GECODE_GENR_FUNC
(
asinh
)
85
GECODE_GENR_FUNC
(
acosh
)
86
GECODE_GENR_FUNC
(
atanh
)
87
88
#undef GECODE_GENR_FUNC
89
90
}}
91
92
#endif
93
94
// STATISTICS: float-var
95
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::log
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
transcendental.cpp:57
Gecode::tanh
FloatVal tanh(const FloatVal &x)
Definition:
val.hpp:472
Gecode::acosh
FloatVal acosh(const FloatVal &x)
Definition:
val.hpp:480
Gecode::sin
void sin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:56
Gecode::asinh
FloatVal asinh(const FloatVal &x)
Definition:
val.hpp:476
Gecode::acos
void acos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:63
Gecode
Gecode toplevel namespace
float.hh
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:110
Gecode::tan
void tan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:84
Gecode::sinh
FloatVal sinh(const FloatVal &x)
Definition:
val.hpp:464
Gecode::atanh
FloatVal atanh(const FloatVal &x)
Definition:
val.hpp:484
Gecode::Float::mpfr_func
int mpfr_func(mpfr_t, const __mpfr_struct *, mp_rnd_t)
Type signatur of mpfr function.
Definition:
rounding.cpp:52
GECODE_GENR_FUNC
#define GECODE_GENR_FUNC(name)
Define mpfr functions with proper rounding.
Definition:
rounding.cpp:66
Gecode::asin
void asin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:49
Gecode::cosh
FloatVal cosh(const FloatVal &x)
Definition:
val.hpp:468
Gecode::atan
void atan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:77
Gecode::f
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Gecode::exp
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
transcendental.cpp:49
Gecode::cos
void cos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
trigonometric.cpp:70
Gecode::Float::invoke_mpfr
double invoke_mpfr(FloatNum x, mpfr_func f, mp_rnd_t r)
Routine to call mpfr function with proper rounding.
Definition:
rounding.cpp:56