From ok@atlas.otago.ac.nz  Fri May  5 00:43:08 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 AAA06101
	for <prolog@swi.psy.uva.nl>; Fri, 5 May 2000 00:43:06 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id KAA02133;
	Fri, 5 May 2000 10:43:12 +1200 (NZST)
Date: Fri, 5 May 2000 10:43:12 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200005042243.KAA02133@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, timm@csee.wvu.edu
Subject: Re:  handling small numbers

Tim Menzies <timm@csee.wvu.edu> wrote:
	got an error in my prolog code in the 20th decimal place and was wondering
	was i can do about it. ...
	my current approach is to code it all as fractions doing gcd and
	defer real number calcs till as late as possible,

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.

You might pick up the DEC-10 Prolog library, which contains a package
LONG.PL for doing rational arithmetic.  That may need a wee bit of
tuning; IIRC it assumes that 10**10 can be represented as an integer
(because on a DEC-10, it _could_), so you may have to change the
magic number 100000 to 10000 or even 1000 throughout.
But that still leaves you with the problem of converting an exact ratio to
a floating point number, and there you run into the problem that
exact integers can be too big to fit into a floating-point number.
That wasn't a problem in DEC-10 Prolog, because DEC-10 Prolog didn't
have floating point arithmetic.  I didn't worry about it at Quintus
simply because I never thought of it.

Someone posting from a *.edu site may possibly have access to a numerical
analyst.  There is a numerical analysis newsgroup; sci.num-anal if I
remember correctly.  Posting a more detailed description of the calculations
there may result in some useful advice.

