Loading...
Searching...
No Matches
gmpfield.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_GMPFIELD_HH
#define DUNE_GMPFIELD_HH
#include <iostream>
#include <string>
#include <type_traits>
#if HAVE_GMP || DOXYGEN
#include <gmpxx.h>
#include <dune/common/math.hh>
#include <dune/common/promotiontraits.hh>
#include <dune/common/typetraits.hh>
namespace Dune
{
template< unsigned int precision >
class GMPField
: public mpf_class
{
typedef mpf_class Base;
public:
GMPField ()
: Base(0,precision)
{}
GMPField ( const char* str )
: Base(str,precision)
{}
GMPField ( const std::string& str )
: Base(str,precision)
{}
template< class T,
typename EnableIf = typename std::enable_if<
std::is_convertible<T, mpf_class>::value>::type
>
GMPField ( const T &v )
: Base( v,precision )
{}
// type conversion operators
operator double () const
{
return this->get_d();
}
};
template <unsigned int precision>
struct IsNumber<GMPField<precision>>
: public std::integral_constant<bool, true> {
};
template< unsigned int precision1, unsigned int precision2 >
struct PromotionTraits<GMPField<precision1>, GMPField<precision2>>
{
typedef GMPField<(precision1 > precision2 ? precision1 : precision2)> PromotedType;
};
template< unsigned int precision >
struct PromotionTraits<GMPField<precision>,GMPField<precision>>
{
typedef GMPField<precision> PromotedType;
};
template< unsigned int precision, class T >
struct PromotionTraits<GMPField<precision>, T>
{
typedef GMPField<precision> PromotedType;
};
template< class T, unsigned int precision >
struct PromotionTraits<T, GMPField<precision>>
{
typedef GMPField<precision> PromotedType;
};
template< unsigned int precision >
struct MathematicalConstants<GMPField<precision>>
{
static_assert(precision < 3319u, "Mathematical constants for GMPField defined up to a precision 3318."); // 1000 digits10
using T = GMPField<precision>;
static const T e ()
{
static const T e = T("2. ");
return e;
}
static const T pi ()
{
static const T pi = T("3. ");
return pi;
}
};
}
#endif // HAVE_GMP
#endif // #ifndef DUNE_GMPFIELD_HH
typetraits.hh
Traits for type conversions and type information.
promotiontraits.hh
Compute type of the result of an arithmetic operation involving two different number types.
math.hh
Some useful basic math stuff.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::IsNumber
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition typetraits.hh:194
Dune::GMPField
Number class for high precision floating point number using the GMP library mpf_class implementation.
Definition gmpfield.hh:34
Dune::GMPField::GMPField
GMPField(const T &v)
initialize from a compatible scalar type
Definition gmpfield.hh:63
Dune::GMPField::GMPField
GMPField()
Definition gmpfield.hh:39
Dune::GMPField::GMPField
GMPField(const std::string &str)
initialize from a string
Definition gmpfield.hh:53
Dune::GMPField::GMPField
GMPField(const char *str)
initialize from a string
Definition gmpfield.hh:46
Dune::PromotionTraits< GMPField< precision1 >, GMPField< precision2 > >::PromotedType
GMPField<(precision1 > precision2 ? precision1 :precision2)> PromotedType
Definition gmpfield.hh:83
Dune::PromotionTraits< GMPField< precision >, GMPField< precision > >::PromotedType
GMPField< precision > PromotedType
Definition gmpfield.hh:89
Dune::PromotionTraits< GMPField< precision >, T >::PromotedType
GMPField< precision > PromotedType
Definition gmpfield.hh:95
Dune::PromotionTraits< T, GMPField< precision > >::PromotedType
GMPField< precision > PromotedType
Definition gmpfield.hh:101
Dune::MathematicalConstants< GMPField< precision > >::e
static const T e()
Definition gmpfield.hh:110
Dune::MathematicalConstants< GMPField< precision > >::T
GMPField< precision > T
Definition gmpfield.hh:109
Dune::MathematicalConstants< GMPField< precision > >::pi
static const T pi()
Definition gmpfield.hh:116
Dune::MathematicalConstants
Provides commonly used mathematical constants.
Definition math.hh:67
Dune::PromotionTraits
Compute type of the result of an arithmetic operation involving two different number types.
Definition promotiontraits.hh:27
Dune::type