Dune Core Modules (2.9.1)

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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_GMPFIELD_HH
6#define DUNE_GMPFIELD_HH
7
12#include <iostream>
13#include <string>
14#include <type_traits>
15
16#if HAVE_GMP || DOXYGEN
17
18#include <gmpxx.h>
19
22
23namespace Dune
24{
25
30 template< unsigned int precision >
32 : public mpf_class
33 {
34 typedef mpf_class Base;
35
36 public:
39 : Base(0,precision)
40 {}
41
45 GMPField ( const char* str )
46 : Base(str,precision)
47 {}
48
52 GMPField ( const std::string& str )
53 : Base(str,precision)
54 {}
55
58 template< class T,
59 typename EnableIf = typename std::enable_if<
60 std::is_convertible<T, mpf_class>::value>::type
61 >
62 GMPField ( const T &v )
63 : Base( v,precision )
64 {}
65
66 // type conversion operators
67 operator double () const
68 {
69 return this->get_d();
70 }
71
72 };
73
74 template <unsigned int precision>
75 struct IsNumber<GMPField<precision>>
76 : public std::integral_constant<bool, true> {
77 };
78
79 template< unsigned int precision1, unsigned int precision2 >
80 struct PromotionTraits<GMPField<precision1>, GMPField<precision2>>
81 {
82 typedef GMPField<(precision1 > precision2 ? precision1 : precision2)> PromotedType;
83 };
84
85 template< unsigned int precision >
86 struct PromotionTraits<GMPField<precision>,GMPField<precision>>
87 {
88 typedef GMPField<precision> PromotedType;
89 };
90
91 template< unsigned int precision, class T >
92 struct PromotionTraits<GMPField<precision>, T>
93 {
94 typedef GMPField<precision> PromotedType;
95 };
96
97 template< class T, unsigned int precision >
98 struct PromotionTraits<T, GMPField<precision>>
99 {
100 typedef GMPField<precision> PromotedType;
101 };
102}
103
104#endif // HAVE_GMP
105
106#endif // #ifndef DUNE_GMPFIELD_HH
Number class for high precision floating point number using the GMP library mpf_class implementation.
Definition: gmpfield.hh:33
GMPField(const T &v)
initialize from a compatible scalar type
Definition: gmpfield.hh:62
GMPField()
Definition: gmpfield.hh:38
GMPField(const std::string &str)
initialize from a string
Definition: gmpfield.hh:52
GMPField(const char *str)
initialize from a string
Definition: gmpfield.hh:45
Dune namespace.
Definition: alignedallocator.hh:13
Compute type of the result of an arithmetic operation involving two different number types.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)