Path: utzoo!utgpu!cunews!cognos!alanm From: alanm@cognos.UUCP (Alan Myrvold) Newsgroups: comp.lang.perl Subject: Re: Arithmetic functions Message-ID: <9381@cognos.UUCP> Date: 28 Feb 91 00:29:53 GMT References: <1991Feb22.215921.16411@uvaarpa.Virginia.EDU> <588@sunny.ucdavis.edu> Reply-To: alanm@cognos.UUCP (Alan Myrvold) Organization: Cognos Inc., Ottawa, Canada Lines: 29 In article <588@sunny.ucdavis.edu> poage@sunny.ucdavis.edu (Tom Poage) writes: >Not too much too add ... > > sub floor { (floor and ceil deleted) And of course : # Round($x,$p) : returns $x rounded to $p decimal places # if $p is omitted, $p = 0 is used # round to nearest, if halfway round to +infinity # if $p < 0, the last $p digits of the result are 0 sub round { local ($x,$p) = @_; local ($ten_p) = 10**$p; $x = .5 + $x*$ten_p; $x-- if $x < 0 && $x != int $x; $x = int($x) / $ten_p; ($p > 0) ? sprintf("%.15g",$x) : $x; } - Alan --- Alan Myrvold 3755 Riverside Dr. uunet!mitel!cunews!cognos!alanm Cognos Incorporated P.O. Box 9707 alanm%cognos.uucp@ccs.carleton.ca (613) 738-1440 x5530 Ottawa, Ontario CANADA K1G 3Z4