I stand better informed than I really wanted to be,
and only quacking quietly from getting my mind round
the implications of these rather complex rules.
(They remind me of PL/1 automatic conversions which were
designed by IBM sales managers to sell computers
but ended up being a maze of snares for the unwary.)

This scheme may offer more surprises to the many naive users (like me)
than an explicit (and convenient 'global') choice, for example:

using boost::math::double_constants;

to ensure that the expected size is used.

One can make the compiler warn you about size conversions,
whereas I have the impression that these rules will mean
that you won't get any warnings.

Paul

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria LA8 8AB  UK
+44 1539 561830
[EMAIL PROTECTED]

|  -----Original Message-----
|  From: [EMAIL PROTECTED] 
|  [mailto:[EMAIL PROTECTED] On Behalf Of Gennaro Prota
|  Sent: 19 June 2003 11:10
|  To: [EMAIL PROTECTED]
|  Subject: [boost] Re: Math Constants Formal Review - does 
|  static_cast merely select?
|  
|  
|  On Wed, 18 Jun 2003 22:27:27 +0100, "Paul A Bristow" 
|  <[EMAIL PROTECTED]> wrote:
|  
|  >|  -----Original Message-----
|  >|  From: [EMAIL PROTECTED]
|  >|  [mailto:[EMAIL PROTECTED] On Behalf Of Gennaro Prota
|  >|  [...]
|  >|  
|  >|  In Daniel's solution static_cast<type>(x) simply "selects"
|  >|  the corresponding specialization of x_value. So
|  >|  
|  >|    static_cast<float>(pi)
|  >|  
|  >|  is fundamentally different from, say,
|  >|  
|  >|    double pi = ...;
|  >|    static_cast<float>(pi)
|  >
|  >Perhaps naively, I find this surprising - but I am not a 
|  language guru.
|  >
|  >Can you/anyone confirm that this is required by the Standard
|  > - and is in fact what happens when compilers process this?
|  
|  Yes :-) Note that all "conversions" from a constant<T, F> 
|  pass through
|  
|    template< typename U > operator U() const { return F< U >()(); }
|  
|  Now, F<U>()() means (ignoring some technical differences irrelevant
|  here):
|  
|    F<U> object;   // construct an x_value<U> object
|    return object(); // invoke operator() on it and return
|  
|  Now, if you use the binary operators, like in:
|  
|   pi * f;
|  
|  with f being a float then the selected specialization is 
|  float; i.e. the constant "takes the type" of its adjacent 
|  operand (left operand if it exists, right operand 
|  otherwise). This is, of course, different from what normally 
|  happens when you do
|  
|    double pi = ...;
|    pi * f;   // floating point promotion on f
|  
|  and is IMHO a caveat. But, still, there are no truncations. 
|  Only selection of the target specialization. If no target 
|  specialization exists, e.g.
|  
|    static_cast<int>(pi)
|  
|  you have a compile-time error.
|  
|  >
|  >If it walks like a duck and quacks like a duck ...
|  
|  This walks quite differently. And doesn't quack :-)
|  
|  
|  Genny.
|  
|  _______________________________________________
|  Unsubscribe & other changes: 
|  http://lists.boost.org/mailman/listinfo.cgi/b|  oost
|  


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to