Skip to content
Snippets Groups Projects
Commit 8e7dabc8 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

[!800] Define promotion traits involving GMPField types

Merge branch 'issue/gmp_promotion_traits' into 'master'

ref:core/dune-common\>

### Summary

Define missing promotion traits involving GMPField types

### Details

Whenever a GMPField is used as a field type in FieldVector, arithmetic
operations with this vector involve the determination of promotion types for
GMField with another GMPField or with another scalar. Since the promotion
types are defined by `decltype(a + b)` the result is a gmp_expr that cannot be
put into a vector.

This MR defines the promotion types, by taking the GMPField with the highest
precision if two gmp's are involved, if combined with another type, always
prefer the GMPField. This is not optimal, since another type could have higher
precision than the GMPField, but this is not so easy to detect.

See merge request [core/dune-common!800]

  [core/dune-common!800]: gitlab.dune-project.org/core/dune-common/merge_requests/800
parents a9a76514 17f6ee14
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
#include <gmpxx.h>
#include <dune/common/promotiontraits.hh>
#include <dune/common/typetraits.hh>
namespace Dune
......@@ -73,6 +74,29 @@ namespace Dune
: 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;
};
}
#endif // HAVE_GMP
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment