[CppAD] Own Data Type

Dominik Skanda Dominik.Skanda at biologie.uni-freiburg.de
Wed Mar 2 05:13:55 EST 2011


Hello,

thank you for your answer,



Am Dienstag, den 01.03.2011, 15:03 -0800 schrieb Robert P. Goddard:
> This thread is troublesome in several respects.
> 
> First, Dominik presents a class he calls MyType, which contains a single 
> member "d" of type qd_real, and defines a whole lot of standard 
> operations on it -- all of which simply delegate the operation to d.  
> Why does MyType exist at all? If you are going to use it with CppAD, why 
> not CppAD<qd_real> instead of CppAD<MyType>?


I would like to use CppAD<qd_real> instead of the indirect way by use of
the class MyType. My problem is that its not working at least in the
very direct way by just using CppAD<qd_real>. With the Mytype class its
working now.



> 
> Second, Dominik's second message asks about the effect of the expression
> 
> Y[0]=X[0]-234.123456789123456789123456789123456789;
> 
> The C++ standard (old and new) tell us unambiguously what that means: 
> The long constant on the right is a double, pure and simple, and it 
> retains only the precision native to a double -- silently. The C++ 2010 
> Draft of 8/21/2010 says in part 2.14.4 "Floating Literals:
> 
> > The type of a floating literal is double unless explicitly specified 
> > by a suffix. The suffixes f and F specify float, the suffixes l and L 
> > specify long double.
> 
> If you want the compiler to recognize the extra digits in your constant, 
> you MUST use the "L" or "l" suffix -- which works if and only if your 
> compiler recognizes the "long double" type defined in the new 
> proto-standard C++. And then it works only to the extent that the 
> built-in type has enough precision to represent a qd_real, AND qd_real 
> has a "-" operation that recognizes "long double", or a non-"explicit" 
> conversion constructor with argument of type "long double". Which this 
> one doesn't have. So it's a double.
> 
> Take-away message: Literals are defined by the language, and must be 
> supported by the compiler. If you really want your mega-precision number 
> to be initialized to full precision, the obvious way to do it is define 
> a constructor that takes a string argument. In that case, the expression 
> above would take the form
> 
> Y[0]=X[0]-MyType("234.123456789123456789123456789123456789");
> 
> All of this is independent of CppAD. It's just C++.
> 




Thank you very much this clarified a lot to me!




> Bob Goddard
> 
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad



Regards,

Dominik



More information about the CppAD mailing list