From ok@atlas.otago.ac.nz  Wed May 10 04:57:12 2000
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id EAA07496
	for <prolog@swi.psy.uva.nl>; Wed, 10 May 2000 04:57:10 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id OAA31206;
	Wed, 10 May 2000 14:57:08 +1200 (NZST)
Date: Wed, 10 May 2000 14:57:08 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200005100257.OAA31206@atlas.otago.ac.nz>
To: ino-waiting@gmx.net, prolog@swi.psy.uva.nl
Subject: Re: handling small numbers

"clemens" wrote
	couldn't the matter be settled by providing a "bigint" package in the
	distribution?

No.  The question is what *normal* integer arithmetic should do.
It has been possible to go off and do something else for longer than
SWI Prolog has existed, thanks to the freely available LONG.PL.

The practical problem is "What happens if I develop my program in a
64-bit version of Prolog and it is run by someone using a 32-bit
version of Prolog?"  This is, as it happens, a live problem for me.
This e-message comes from a 64-bit machine, where I have a Prolog system
installed.  The machine on my desk that I'm actually typing on is a
32-bit machine, soon (I hope) to be upgraded to a 64-bit machine.  The
students use a mix of 32-bit Linux boxes, 32-bit Macs, and 64-bit machines.
Prolog on the 64-bit machines *has* to handle 64-bit integers or it can't
talk to C properly.  But if I test my programs on the 64-bit machines,
and they fail mysteriously on the Linux boxes, that's going to cause
real problems.

	everybody knows about the different qualities of native
	floats and ints.

Apparently not.  Some designers apparently think it is ok to quietly
substitute one for the other without the programmer's say-so.

Here's an example which would confuse our 3rd year students a lot:

	quotient_and_remainder(A, B, C, D, Q, R) :-
	    /* A*B+C = Q*D+R */
	    (   integer(A), integer(B), integer(C),
	        integer(D), D > 0
	    ->
		T is A*B+C,
		Q is T // D,
		R is T mod D
	    ;   abort % better to raise an exception
	    ).

Suppose this is written by someone who *IS* hip to the different
qualities of native floats and ints.  (It was.)  Suppose it is
even tested:
    ?- quotient_and_remainder(17, 1, 0, 5, Q, R).
    Q = 3
    R = 2 
The semantics is nailed down:  // and mod require integer arguments,
and by gum, there's code there to make sure they get 'em.

Not.  At least, not in SWI Prolog.  Because one day,

    ?- quotient_and_remainder(70000, 70000, 0, 10000, Q, R).

blows up:
    ERROR: ///2: Type error: `integer' expected, found `4.9e+09'
    ^  Exception: (7) _G454 is 4.9e+09//10000 ? 

You see, silently converting integers to floats doesn't just introduce
a little bit of fuzziness here and there.  IT PREVENTS YOU DOING
FURTHER INTEGER ARITHMETIC.

From my point of view, the problem here is a bug in SWI Prolog.
It has raise the wrong exception and the wrong point.
The *real* problem is that the multiplication of 70000 by 70000
overflowed.

Anything that separates the symptom from the cause is regrettable.

