Thread View: net.lang.pascal
1 messages
1 total messages
Started by janney
Sat, 25 Feb 1984 17:12
correction to truncating reals
Author: janney
Date: Sat, 25 Feb 1984 17:12
Date: Sat, 25 Feb 1984 17:12
25 lines
1424 bytes
1424 bytes
[] 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads