Rheolef  7.1
an efficient C++ finite element environment
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
3 //
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 // -----------------------------------------------------------------
44 namespace boost{ namespace multiprecision{ namespace backends{
45 template<>
46 inline 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 // ---------------------------------------------------------
56 namespace CGAL {
57 using boost::multiprecision::float128;
58 
59 template<>
60 class Is_valid<float128>: public std::unary_function<float128,bool> {
61 public:
62  bool operator()( const float128& x ) const { return ! boost::math::isnan(x); }
63 };
64 
65 template<>
66 class Algebraic_structure_traits<float128>
67  : public Algebraic_structure_traits_base<float128,Field_with_kth_root_tag> {
68 public:
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 };
84 template<>
85 class Real_embeddable_traits<float128>
86  : public INTERN_RET::Real_embeddable_traits_base<float128,CGAL::Tag_true> {
87 public:
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 };
101 inline
102 bool
103 is_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.
109 inline
110 std::pair<float128, float128>
111 split_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
124 inline
125 float128
126 nextafter(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
boost
Definition: mpi_pair_datatype.h:46
mkgeo_ball.d
int d
Definition: mkgeo_ball.sh:154
rheolef::pow
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:120