DUNE PDELab (2.8)

gmpfield.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GMPFIELD_HH
4#define DUNE_GMPFIELD_HH
5
10#include <iostream>
11#include <string>
12#include <type_traits>
13
14#if HAVE_GMP || DOXYGEN
15
16#include <gmpxx.h>
17
20
21namespace Dune
22{
23
28 template< unsigned int precision >
30 : public mpf_class
31 {
32 typedef mpf_class Base;
33
34 public:
37 : Base(0,precision)
38 {}
39
43 GMPField ( const char* str )
44 : Base(str,precision)
45 {}
46
50 GMPField ( const std::string& str )
51 : Base(str,precision)
52 {}
53
56 template< class T,
57 typename EnableIf = typename std::enable_if<
58 std::is_convertible<T, mpf_class>::value>::type
59 >
60 GMPField ( const T &v )
61 : Base( v,precision )
62 {}
63
64 // type conversion operators
65 operator double () const
66 {
67 return this->get_d();
68 }
69
70 };
71
72 template <unsigned int precision>
73 struct IsNumber<GMPField<precision>>
74 : public std::integral_constant<bool, true> {
75 };
76
77 template< unsigned int precision1, unsigned int precision2 >
78 struct PromotionTraits<GMPField<precision1>, GMPField<precision2>>
79 {
80 typedef GMPField<(precision1 > precision2 ? precision1 : precision2)> PromotedType;
81 };
82
83 template< unsigned int precision >
84 struct PromotionTraits<GMPField<precision>,GMPField<precision>>
85 {
86 typedef GMPField<precision> PromotedType;
87 };
88
89 template< unsigned int precision, class T >
90 struct PromotionTraits<GMPField<precision>, T>
91 {
92 typedef GMPField<precision> PromotedType;
93 };
94
95 template< class T, unsigned int precision >
96 struct PromotionTraits<T, GMPField<precision>>
97 {
98 typedef GMPField<precision> PromotedType;
99 };
100}
101
102#endif // HAVE_GMP
103
104#endif // #ifndef DUNE_GMPFIELD_HH
Number class for high precision floating point number using the GMP library mpf_class implementation.
Definition: gmpfield.hh:31
GMPField(const T &v)
initialize from a compatible scalar type
Definition: gmpfield.hh:60
GMPField()
Definition: gmpfield.hh:36
GMPField(const std::string &str)
initialize from a string
Definition: gmpfield.hh:50
GMPField(const char *str)
initialize from a string
Definition: gmpfield.hh:43
Traits for type conversions and type information.
Dune namespace.
Definition: alignedallocator.hh:11
Compute type of the result of an arithmetic operation involving two different number types.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 24, 22:29, 2024)