Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
cgal_kernel_float128.h
Go to the documentation of this file.
1#ifndef _RHEO_CGAL_KERNEL_FLOAT128_H
2#define _RHEO_CGAL_KERNEL_FLOAT128_H
23//
24// Defines a cgal kernel for boost::multiprecision::float128
25//
26#if defined(_RHEOLEF_HAVE_FLOAT128) && defined(_RHEOLEF_HAVE_CGAL)
27#include "rheolef/compiler.h"
28#include <CGAL/utils.h>
29#include <CGAL/utils_classes.h>
30#include <CGAL/number_utils.h>
31#include <CGAL/Gmpq.h>
32
33#include <utility>
34#include <cmath>
35#include <limits>
36
37#ifdef TODO
38#include <math.h> // for nextafter
39#endif // TODO
40
41// -----------------------------------------------------------------
42// extend boost/multiprecision/float128.hpp to work with CGAL::gmpq
43// -----------------------------------------------------------------
44namespace boost{ namespace multiprecision{ namespace backends{
45template<>
46inline void eval_convert_to(CGAL::Gmpq* result, const float128_backend& val)
47{
48 // TODO CGAL: float128 -> double -> gmpq: not ideal but try it
49 *result = static_cast<CGAL::Gmpq>(double(val.value()));
50}
51}}} // namespace boost::multiprecision::backends
52
53// ---------------------------------------------------------
54// extend CGAL to work with boost::multiprecision::float128
55// ---------------------------------------------------------
56namespace CGAL {
57using boost::multiprecision::float128;
58
59template<>
60class Is_valid<float128>: public std::unary_function<float128,bool> {
61public:
62 bool operator()( const float128& x ) const { return ! boost::math::isnan(x); }
63};
64
65template<>
66class Algebraic_structure_traits<float128>
67 : public Algebraic_structure_traits_base<float128,Field_with_kth_root_tag> {
68public:
69 typedef Tag_false Is_exact;
70 typedef Tag_true Is_numerical_sensitive;
71
72 class Sqrt: public std::unary_function<Type,Type> {
73 public:
74 Type operator() (const Type& x) const { return sqrt(x); }
75 };
76 class Kth_root: public std::binary_function<int,Type,Type> {
77 public:
78 Type operator() (int k, const Type& x) const {
79 CGAL_precondition_msg(k > 0, "'k' must be positive for k-th roots");
80 return pow(x, 1.0/float128(k));
81 }
82 };
83};
84template<>
85class Real_embeddable_traits<float128>
86 : public INTERN_RET::Real_embeddable_traits_base<float128,CGAL::Tag_true> {
87public:
88 class Abs: public std::unary_function<Type,Type> {
89 public:
90 Type operator() (const Type& x) const {
91 return fabs(x);
92 }
93 };
94 class Is_finite: public std::unary_function<Type,bool> {
95 public :
96 bool operator() (const Type& x) const {
97 return boost::math::isfinite(x);
98 }
99 };
100};
101inline
102bool
103is_integer(float128 d)
104{
105 return boost::math::isfinite(d) && (ceil(d) == d);
106}
107
108// Returns a pair of integers <num,den> such that d == num/den.
109inline
110std::pair<float128, float128>
111split_numerator_denominator(float128 d)
112{
113 // Note that it could probably be optimized.
114 float128 num = d;
115 float128 den = 1.0;
116 while (ceil(num) != num) {
117 num *= 2.0;
118 den *= 2.0;
119 }
120 CGAL_postcondition(d == num/den);
121 return std::make_pair(num, den);
122}
123#ifdef TODO
124inline
125float128
126nextafter(float128 d1, float128 d2)
127{
128 return ::nextafter(d1,d2);
129}
130#endif // TODO
131
132} //namespace CGAL
133#endif // _RHEOLEF_HAVE_FLOAT128 && _RHEOLEF_HAVE_CGAL
134#endif // _RHEO_CGAL_KERNEL_FLOAT128_H
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition space_mult.h:120
t operator()(const t &a, const t &b)
Definition space.cc:386