From jan@swi.psy.uva.nl  Fri May  5 13:15:07 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id NAA14952;
	Fri, 5 May 2000 13:15:07 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id NAA01932;
	Fri, 5 May 2000 13:15:14 +0200
Date: Fri, 5 May 2000 13:15:14 +0200
Message-Id: <200005051115.NAA01932@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re:  handling small numbers
To: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>, prolog@swi.psy.uva.nl,
        timm@csee.wvu.edu
In-Reply-To: Richard A. O'Keefe's message of Fri, 5 May 2000 10:43:12 +1200 (NZST)
Phone: +31 - 20 - 525 6121

> This leaves you with a couple of problems.
> First, exact rational calculations tend to give you large
> numerators and denominators, and SWI Prolog arithmetic is,
> um, a bit unpleasant there.
> 	?- X is 1000*1000*1000*1000.
> 	X = 1e+12 		% why isn't it 1000000000000?
> 	Yes			% maybe that's how bignums print??
> 	?- X is 1000*1000*1000*1000, integer(X).
> 	No			% nope, it realy did float it.
> So if you calculate your numerators and denominators _directly_,
> SWI Prolog is going to screw you with floating point arithmetic
> anyway.

SWI-Prolog its are 32-bits, so X is 1000*1000*1000*1000 has a problem.
There are two solutions: raise an exception or promote to a float (=
C double).  I've choosen for the latter for `convience'.  In many cases
you get more or less the proper result.  Only if you want to be precise
you'll need some extra checks and handle numbers with care.

This however works nice:

	X is (1000*1000*1000*1000)/200000, integer(X).

	X = 5000000

Please note that some of this behaviour depends on the `iso' prolog
flag, (actually I think it should raise an exception in ISO mode).

	Regards --- Jan

