Re: int2interval, frac2interval, rat2interval
On 2012-04-19 07:05:18 -0700, Dmitry Nadezhin wrote:
> > This is not Level 2 yet, but I suppose that what is an integer will be
> > language-defined. I mean, it can come from an integer type,
>
> I thought that int2interval(i) is a pattern and that an
> implementation may define variants of this operation for any integer
> type:
>
> short2interval(short s);
> int2interval(int i);
> long2interval(long l);
> mpz2interval(mpz_t z);
Some languages have only a number type. For instance, ECMAScript just
has binary64 (with a single NaN, so that would be Level 2). Those who
want to compute on integers use this type, since it can represent all
integers between -2^53 and 2^53. Some other languages, like Perl, are
very weakly typed.
But I think that if some form of int2interval(i) is used, this means
than i must be an integer (which has normally been computed exactly).
So, there would be nothing wrong by defining it in ECMAScript or Perl
with their number (ECMAScript) or scalar (Perl) type (see below).
> Each implemented variant must conform P1788 rules.
>
> I missed the question "which of these variants are required ?".
> I see 2 ways how to fix them:
> a) int2interval(i) and frac2interval(p,q) are also recommended
> operations (as rat2interval);
> b) prepare some rules for int formats (similar to double formats).
>
> My preference is (a).
> Does anybody need int2rational(i) or frac2rational(p,q) as required
> operation ?
I think it could be (b) with very simple rules:
* the type contains integers, and possibly other values (numeric
or not).
* int2interval(i) is specified on integer values by P1788.
* On other values, int2interval(i) returns NaI (if accepted for
other constructors).
Note: in practice, the type can provide infinities, but they should
be seen as other values, because infinities cannot be produced in a
correct integer expression.
> > or from some floating-point number (if it happens to be an
> > integer) if the language doesn't have a specific integer type.
>
> I understand this that constructors
> float2interval(float f)
Actually in such languages, this is just called "number" (it can
be implemented in FP, but there can be a mix of different numeric
types). That would be: number2interval(x).
> or
> Interval(float f)
> are allowed but they must throw an exception when f is not exact
> integer value.
IMHO, the behavior should be similar to the other constructors on
"invalid" input, thus NaI.
> I doesn't seem good for me, because it can't be static typechecked.
I don't understand what you mean. Not everything can be done
statically, even in fully-typed languages. For instance, you
cannot always statically check that l <= u. And concerning
integers, you cannot always statically check that the integer
you got is correct (e.g. you may have had an integer overflow).
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)