From: csus.edu!wupost!spool.mu.edu!munnari.oz.au!metro!cluster!swift!sunaus!ass ip.csasyd!condor!daves@ucdavis.ucdavis.edu (Dave Smart)
Subject: Re: Red-faced professor gets bitten in search for portability
Date: 25 Nov 91 06:09:00 GMT [thread overview]
Message-ID: <daves.691049340@condor> (raw)
To follow up my own post, I've been reminded that my algorithm - and Mike
Murphy's and both of Mike Feldman's - don't reproduce the Pascal trunc action
for negative numbers. E.g. -3.75 becomes -4 rather than -3. In my own case, o
f
course, I was simply reproducing the action of Mike Murphy's algorithm :-).
There are tricky ways of getting the result right for negative values. In
Pascal, I'd probably use the abs () and sign () functions. However, KISS:
function trunc (number: float) return integer is
begin
if number >= 0.0 then -- positive cases
if float (integer (number)) > number then -- does it round up?
return integer (number) - 1; -- yes - stop it!
else
return integer (number); -- no - ok as it is.
end if;
else -- negative cases
if float (integer (number)) < number then -- does it round down?
return integer (number) + 1; -- yes - stop it!
else
return integer (number); -- no - ok as it is.
end if;
end if;
end trunc;
Dave
--
David Smart, Computer Sciences of Australia.
Net: daves@assip.csasyd.oz.au
next reply other threads:[~1991-11-25 6:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-11-25 6:09 csus.edu!wupost!spool.mu.edu!munnari.oz.au!metro!cluster!swift!sunaus!ass [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-11-22 22:16 Red-faced professor gets bitten in search for portability Dik T. Winter
1991-11-22 22:11 Dik T. Winter
1991-11-22 21:10 Jonathan Parker
1991-11-22 15:24 The Sunset Kid
1991-11-22 14:06 psinntp!vitro.com!v7.vitro.com!vaxs09
1991-11-22 2:29 micro-heart-of-gold.mit.edu!wupost!zaphod.mps.ohio-state.edu!uakari.prima
1991-11-20 23:59 micro-heart-of-gold.mit.edu!wupost!sdd.hp.com!uakari.primate.wisc.edu!use
1991-11-20 2:55 csus.edu!wupost!cs.utexas.edu!sun-barr!cronkite.Central.Sun.COM!newstop!s
1991-11-19 15:06 Norman H. Cohen
1991-11-16 0:01 Michael Feldman
1991-11-15 20:58 Mike Murphy
1991-11-15 18:59 Michael Feldman
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox