Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site unm-cvax.UUCP
Path: utzoo!linus!decvax!mcnc!akgua!clyde!floyd!cmcl2!lanl-a!unm-cvax!janney
From: janney@unm-cvax.UUCP
Newsgroups: net.lang.pascal
Subject: correction to truncating reals
Message-ID: <715@unm-cvax.UUCP>
Date: Sat, 25-Feb-84 12:12:26 EST
Article-I.D.: unm-cvax.715
Posted: Sat Feb 25 12:12:26 1984
Date-Received: Sun, 26-Feb-84 04:54:02 EST
Organization: Univ. of New Mexico, Albuquerque
Lines: 25

[] wombat treat
	A while ago I posted a function that truncates real numbers without
converting them to integers, using only standard Pascal.  This involves
finding the smallest number in the floating point system that does not have
a fractional part.  I did this by

	big:= 1.0;
	while big + 0.4 > big do
	   big:= big * 2.0;

I added 0.4 instead of 0.5 to avoid problems with rounding.  This avoids
trouble with rounding, all right, but it doesn't work on machines that
just truncate.  The following seems to work on both kinds of machine:

	big:= 1.0;
	while (big + 0.5 > big) and (big + 0.5 < big + 1.0) do
	   big:= big * 2.0;

The first condition is for machines that truncate, and the second is for
machines that round.


Jim Janney
{parsec,ucbvax,gatech,aml-mcs,csu-cs,anl-mcs,lanl-a}!unmvax!unm-cvax!janney
{purdue,lbl-csam,cmcl2,csu-cs}!lanl-a!unm-cvax!janney