gbastin@x102c.ess.harris.com (Gary Bastin 60293) (04/05/91)
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. A function ROUND(x,n) could be written for a specific platform, taking advantage of the internal storage technique used by a particular compiler, and which would basicly round the mantissa to n-digits, leaving the exponent unaffected (for n <= the maximum number of digits possible for the data type). But, 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!
jerry@violet.berkeley.edu (Jerry Berkman) (04/06/91)
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