From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 25 Nov 91 06:09:00 GMT 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 Message-ID: List-Id: 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