[Dune-devel] [Dune-Commit] [Commit] dune-geometry - cb66db8: Add explicit conversion, needed when using high precision types like boost::multiprecision

Martin Nolte nolte at mathematik.uni-freiburg.de
Fri Jun 13 13:28:19 CEST 2014


Hi Andreas,

your point about expression templates is indeed an interesting observation. In 
my opinion, the need to use of ctype( 0 ) is obvious. However, as Christian 
mentioned, df / cxn is the division of two ctypes, so we usually expect the 
result to be ctype. Your compiler output indicates that you have not tested 
the option

ctype dfcxn = (cxn > Traits::tolerance() || cxn < -Traits::tolerance()) ? df / 
cxn : ctype(0);

Does the compiler accept that?

The questions you really comment on is: What assumptions does a "ctype" (or, 
more generally, a field type) have to satisfy? Can they be satisfied by a type 
implementing expression templates (or do I have to enforce their resolution)? 
I think these questions are worthy of a discussion at this year's developer 
meeting.

Best,

Martin


On 06/13/2014 12:14 PM, Andreas Buhr wrote:
> Dear Duners, dear Markus,
>
> On 06/12/2014 07:08 PM, Markus Blatt wrote:
>>>>
>>>>         /* The second case effectively results in x* = 0 */
>>>> -      ctype dfcxn = (cxn > Traits::tolerance() || cxn < -Traits::tolerance()) ? df / cxn : 0;
>>>> +      ctype dfcxn = (cxn > Traits::tolerance() || cxn < -Traits::tolerance()) ? ctype(df / cxn) : ctype(0);
>>>>
>> Sorry for being dense, but I do not get why this is needed and hope to
>> learn something.
>
> I am glad you ask. The problem is indeed quite subtle. I am using the
> code with a "boost::multiprecision::mpf_float_1000" to calculate some
> reference results with 1000 digits accuracy.
>
> "df" and "cxn" are of type "ctype", but that does not mean that "df /
> cxn" is automatically of type "ctype". boost::multiprecision uses
> expression templates, so "df / cxn" becomes an
> "boost::multiprecision::detail::expression". The "?:" operator then sees
> the types (bool|expression|int) and generates an error.
>
> For reference, I attached the complete compile output.
>
> I hope this answers your question?
>
> cheers,
> Andreas
>
>
>
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel
>

-- 
Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5630
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune-devel mailing list