Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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 * 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#include <gecode/float.hh>
39
40#ifdef GECODE_HAS_MPFR
41
42#include <gmp.h>
43#include <mpfr.h>
44
45namespace Gecode { namespace Float {
46
48 typedef int mpfr_func(mpfr_t, const __mpfr_struct*, mp_rnd_t);
49
51 forceinline double
53 mpfr_t xx;
54 mpfr_init_set_d(xx, x, GMP_RNDN);
55 f(xx, xx, r);
56 FloatNum res = mpfr_get_d(xx, r);
57 mpfr_clear(xx);
58 return res;
59 }
60
62#define GECODE_GENR_FUNC(name) \
63 FloatNum Rounding::name##_down(FloatNum x) { \
64 return invoke_mpfr(x, mpfr_##name, GMP_RNDD); \
65 } \
66 FloatNum Rounding::name##_up(FloatNum x) { \
67 return invoke_mpfr(x, mpfr_##name, GMP_RNDU); \
68 }
83
84#undef GECODE_GENR_FUNC
85
86}}
87
88#endif
89
90// STATISTICS: float-var
91
double FloatNum
Floating point number base type.
Definition float.hh:106
Floating point numbers.
int mpfr_func(mpfr_t, const __mpfr_struct *, mp_rnd_t)
Type signatur of mpfr function.
Definition rounding.cpp:48
double invoke_mpfr(FloatNum x, mpfr_func f, mp_rnd_t r)
Routine to call mpfr function with proper rounding.
Definition rounding.cpp:52
Gecode toplevel namespace
FloatVal asinh(const FloatVal &x)
Definition val.hpp:472
void sin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
void cos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void acos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void atan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
FloatVal sinh(const FloatVal &x)
Definition val.hpp:460
FloatVal acosh(const FloatVal &x)
Definition val.hpp:476
FloatVal tanh(const FloatVal &x)
Definition val.hpp:468
void asin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
FloatVal atanh(const FloatVal &x)
Definition val.hpp:480
Post propagator for SetVar x
Definition set.hh:773
FloatVal cosh(const FloatVal &x)
Definition val.hpp:464
void tan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
#define GECODE_GENR_FUNC(name)
Define mpfr functions with proper rounding.
Definition rounding.cpp:62
#define forceinline
Definition config.hpp:194