Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!agate!violet.berkeley.edu!jerry From: jerry@violet.berkeley.edu (Jerry Berkman) Newsgroups: comp.lang.fortran Subject: Re: Arbitrary Digit Arithmetic Message-ID: <1991Apr6.003438.24011@agate.berkeley.edu> Date: 6 Apr 91 00:34:38 GMT References: <6005@trantor.harris-atd.com> Sender: usenet@agate.berkeley.edu (USENET Administrator) Organization: University of California, Berkeley Lines: 27 In article <6005@trantor.harris-atd.com> gbastin@x102c.ess.harris.com (Gary Bastin 60293) writes: >I am looking for a way to perform arbitrary number rounding, >up to the maximum possible for the data type, for arithmetical >operations. For example, assume that 4 digit accuracy is desired >and REAL types are used, giving approximately 6 or 7 digits of >accuracy, depending upon the platform. Then, the problem is to >perform the arithmetic operation, and round the result to 4 digits. >...has anyone got any F77 source code for such a function that would be >portable between platforms? > >Thanks in advance! > >Gary Bastin, WB4YAF /-/-/ Internet: gbastin@x102c.ess.harris.com >Mail Stop 102-4826 | phone: (407) 729-3045 >Harris Corporation GASD | >P.O.B. 94000, Melbourne FL 32902 Speaking from, but not for, Harris! Is this what you want? round(x,n) = anint(x*10**n)/10**n Of course the answers can't be exact because you are trying to "round" to numbers which can not be exactly represented in binary. - Jerry Berkman, U.C. Berkeley, jerry@violet.berkeley.edu, (415)642-4804