Re: Motion 56 -- Level 2, Clauses 12.12.1-12.12.7
On 12/14/2013 01:32 PM, John Pryce wrote:
> Michel
>
> On 2013 Dec 12, at 14:45, Michel Hack wrote:
>>> Using ib64 as short for the inf-sup binary64 type, etc., suppose a programmer
>>> writes an interval operation such as
>>> zz_ib64 = xx_ib32 op yy_ib128 (*)
>>> where "op" is one of the operations required to have "tightest" accuracy.
> 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 C++?
In C++, if interval arithmetic is implemented as a class library,
the class library writer will have to say expressly what to do.
For the C++ compiler, ib64, ib32, and ib128 are entirely distinct
types that are incommensurate. It's the library that offers a
function that implements "op", and also defines the types ib32 etc.
There are essentially two options how "op" can be provided:
- Provide the entire set of combinations of possible input types,
widening the narrower operand in the library implementation as required.
- Provide only
op(ib32, ib32)
op(ib64, ib64)
op(ib128, ib128)
and create an implicit conversion from ib32 to ib64 and ib128,
and from ib64 to ib128.
Obviously, both approaches make the result of "xx_ib32 op yy_ib128" a
value of type "ib128". I would refrain from providing implicit
conversion or assignment to a narrower type (such as ib64), because
it would (potentially) lose information. So, the programmer would
have to say explicitly
zz_ib64 = interval_cast<ib64>(xx_ib32 op yy_ib128)
where "interval_cast" is provided by the library and does the obvious
narrowing.
Jens