[M3devel] Unbounded but finite LONGINT (was: Re: Integers
Jay K
jay.krell at cornell.edu
Sat Jan 9 03:09:13 CET 2010
I hear Hendrik proposing that "LONGINT" is the name for fixed arbitrary precision integers.
That it might even have a name. Or the user has to mention it in order to acknowledge
he is using something potentially inefficient.
FileSize = BITS 64 FOR LONGINT;
FileSize = [1..LongInt.LShift(1, 63)];
FileSize = LONGINT[64];
or such
This is not a bad idea.
I think the "real" problem here is a multitude of options/scenarios and
a lack of vocabulary.
As I said, there is a time/place for "silent wraparound", for trapping overflow,
for extending precision to fit.
Also I'm surprised you can't mix REAL and LONGREAL.
Also I don't think INTEGER + LONGINT is all that confusing or, as I said, subtle.
It isn't /immediately/ obvious how to deal with MIN, MAX, MOD, DIV, but
it is still not that tricky.
MIN(INTEGER, LONGINT) is INTEGER. Not that difficult to figure out why.
At least one of the inputs fits in an integer and the result is the smaller input.
MAX(INTEGER, LONGINT) is LONGINT, ditto.
One of the inputs might not fit in an INTEGER and the result is the larger input.
INTEGER DIV LONGINT is INTEGER
BIG DIV SMALL1 is SMALL2
SMALL DIV BIG is 0 remainder SMALL.
LONGINT DIV INTEGER is LONGINT
Prove with one simple case:
BIG1 DIV 2 is BIG2.
Easier BIG1 DIV 1 is BIG1.
Consider: LONGINT MOD INTEGER and INTEGER MOD LONGINT
SMALL divided by BIG is, again, 0 remainder SMALL, INTEGER
BIG divided by SMALL1 is SMALL2, remainder [0..SMALL1 - 1] which is INTEGER.
That is, division either gives you 0 and remainder = first number.
Or it gives you non-zero and remainder is less than the second number.
50 divided by 100 is 0 remainder 50.
109 divided by 10 is 10 remainder 9
FOR loops also should allow mixing.
- Jay
> Date: Fri, 8 Jan 2010 20:44:37 -0500
> From: hendrik at topoi.pooq.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] Unbounded but finite LONGINT (was: Re: Integers
>
> On Fri, Jan 08, 2010 at 08:33:42PM -0500, hendrik at topoi.pooq.com wrote:
> > On Fri, Jan 08, 2010 at 07:53:07PM -0500, Tony Hosking wrote:
> > > I think what you are advocating is Rodney's proposal + assignability
> > > of INTEGER and LONGINT + mixed arithmetic.
> >
> > I thought Rodney's propsal still had the compiler impose a bound on the
> > size of LONGINT. Or did I miss something?
>
> In particular, I would have there be no FIRST(LONGINT) or LAST(LONGINT).
>
> -- hendrik
> >
> > I'm proposing to let the programmer use subranges of LONGINT that are as
> > long as he wishes. And if the computer runs out of virtual memory to
> > store one of the programmer's long integers, well, that's the computer
> > imposing the limit, not the language.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100109/49c07b7c/attachment-0002.html>
More information about the M3devel
mailing list