QuadMath.hpp 2.32 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once

#if HAVE_QUADMATH
#include <functional>
#include <type_traits>

#include <dune/common/hash.hh>
#include <dune/common/quadmath.hh>

#include <amdis/common/DerivativeTraits.hpp>
#include <amdis/common/StaticSize.hpp>
#include <amdis/common/ValueCategory.hpp>
#include <amdis/gridfunctions/ConstantGridFunction.hpp>

namespace std
{
  template <class T>
  struct common_type<Dune::Float128, T>
  {
    using type = Dune::Float128;
  };

  template <class T>
  struct common_type<T, Dune::Float128>
  {
    using type = Dune::Float128;
  };

  template <>
  struct common_type<Dune::Float128, Dune::Float128>
  {
    using type = Dune::Float128;
  };

  template <>
  struct hash<Dune::Float128>
  {
    typedef Dune::Float128 argument_type;
    typedef std::size_t result_type;

    std::size_t operator()(const Dune::Float128& arg) const
    {
      hash<long double> hasher_ld;
      return hasher_ld((long double)(arg));
    }
  };

  template <>
  struct hash<const Dune::Float128>
      : public hash<Dune::Float128>
  {};

} // end namespace std


namespace Dune
{
  namespace Impl
  {
    // specialization for float arguments due to ambiguity
    template <class T,
      std::enable_if_t<not std::is_integral<T>::value && std::is_arithmetic<T>::value, int> = 0>
    inline Float128 pow(const Float128& x, const T& p)
    {
      return powq(float128_t(x), float128_t(p));
    }

  } // end namespace Impl
} // end namespace Dune


namespace AMDiS
{
  namespace Concepts
  {
    namespace Definition
    {
      template <>
      struct ConstantToGridFunction<Dune::Float128>
        : std::true_type {};

    } // end namespace Definition
  } // end namespace Concepts

  namespace Impl
  {
    template <>
    struct SizeImpl<Dune::Float128>
        : std::integral_constant<std::size_t, 1> {};

    template <>
    struct RowsImpl<Dune::Float128>
        : std::integral_constant<std::size_t, 1> {};

    template <>
    struct ColsImpl<Dune::Float128>
        : std::integral_constant<std::size_t, 1> {};

  } // end namespace Impl

  template <class K, int N>
  struct DerivativeTraits<Dune::Float128(Dune::FieldVector<K,N>), tag::gradient>
  {
    using Range = Dune::FieldVector<Dune::Float128,N>;
  };

  template <>
  struct ValueCategory<Dune::Float128>
  {
    using type = tag::scalar;
  };

} // end namespace AMDiS

#endif // HAVE_QUADMATH