[net.lang.pascal] correction to truncating reals

janney@unm-cvax.UUCP (02/25/84)

[] 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