> < ^ Date: Thu, 30 May 1996 22:48:00 +0100 (MET)
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
< ^ Subject: Re: Minor Bug

David Wood and Sebastian Egner have reported errors that occur when one
tries to construct ranges with entries larger than 2^28-1 or smaller than
-2^28.

GAP represents integers between -2^28 and 2^28-1 (including) as
*immediate integers*, i.e., they are stored directly, whereas larger
integers are represented by a pointer to a memory location where the
large integer is stored. Thus immediate integers must fit into 4
bytes. Since we need 2 bits to be able to distinguish, one bit for the
sign, and one guard bit (to detect overflow), immediate integers are
restricted to the range -2^28 .. 2^28-1.

The first restriction is that ranges must contain only small integers.
When you try to construct a range containing large integers, you get a
misleading error message. This is the problem reported by David Wood.

The next restriction is that the position in '<list>[<position>]' must be
a small (and of course positive) integer. If it isn't, you also get a

```gap> list := [];;
gap> list[ 2^28 ];
Error, List Element: <position> must be a positive integer
```

The final restriction is that *all* lists must have a length < 2^28.
This is of course not a important, given the previous restriction.

While it is possible to contruct some longer ranges, funny things happen
when you do

```gap> list := [-10..2^28-1];
[ -10 .. 268435455 ]
gap> Length( list );
268435466
gap> 2^28+10;
268435466
gap> last = last2;
false
```

This is because the length is represented as immediate integer, even
though it is strictly too large for it. But because of the guard bit,
it still *seems* to work.

It gets worse when one constructs the longest possible range.

```gap> list := [-2^28..2^28-1];;
gap> Length( list );
-536870912
```

When GAP tries to print this list (of negative length) it dies (this
is the problem reported by Sebastian Egner).

```gap> [-2^28..2^28-1];
Segmentation fault
```

Martin.

```-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,   +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, 52056 Aachen, Germany
```

> < [top]