Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Motion 56 -- Level 2, Clauses 12.12.1-12.12.7



John Pryce wrote:
> Avoiding a combinatorial explosion is obviously important.  I'm probably
> showing my ignorance of programming languages here.  Suppose 1788 is
> implemented by a class library.  Suppose the library has "one homogeneous
> form per type" as you say.  How does the library writer tell the compiler
> to widen a statement like (*) in the right way
> - in Fortran?
> - in C++?
> - in some other modern language, e.g. Python?

Experts in those three languages should reply.  In C, for native types
(e.g. float, double, long double) one would use a "cast", e.g.:
      z_b64 = (double)x_b32 +  (double)y_b32;  /* b32 is "float" in C */
(The casts are necessary in this example; in the scalar equivalent of
John's original example (*) default casts to the widest input format
would apply, followed by an implied cast to the target format.)

For non-native types however explicit conversion functions would have
to be used (and P1788 requires their availability):

      zz_ib64 = op_ib64(IB32toIB64(xx_ib32), IB32toIB64(yy_ib32));

For John's original example (*) it would be:

      zz_ib64 = IB128toIB64(op_ib128(IB32toIB128(xx_ib32), yy_ib128));

The implementation could however use macros instead of direct function
invocations, and the op_ib64 etc. macros could use compile-time "type of"
information to plug in the required conversion steps automatically, giving
the appearance of type-generic functions which languages like C++ may offer
as part of the language.

Michel.
---Sent: 2013-12-14 16:16:01 UTC