Everhart, Glenn From: Arne Vajhøj [avajhoej@gtech.com] Sent: Monday, August 31, 1998 7:26 AM To: Jerry Leichter; Info-VAX@Mvb.Saic.Com Subject: Re: DEC C compiler and /FLOAT Jerry Leichter wrote: > Correct. I am a bit puzzled by the use of the word "only", however. > Floating computations that require more than 15 digits of precision are > quite rare. There's probably not a physical quantity around that's > known to that many digits of precision. Even though input has f.ex. only 3 or 4 digits of precision, then a very high precision may be necesarry to keep ths same number of digits precision in the output, if the problem and/or algorithm and/or data is not "nice". Below are an example: - input with 5 digits precision - two mathematical identical algorithms for the same calculation - the calculations are extremely simple (you can do them in 10 seconds with a hand-calculator, if is not 1 million iterations or something fancy) - all calculations are done with REAL*4 that is 7 digits precision - algorithm #2 has zero digits precision in output REAL*4 X(3) REAL*4 VAR1,VAR2 DATA X/9999,10000,10001/ WRITE(*,*) VAR1(3,X) WRITE(*,*) VAR2(3,X) END C REAL*4 FUNCTION VAR1(N,X) INTEGER*4 N REAL*4 X(*) INTEGER*4 I REAL*4 M,V M = 0 DO 100 I=1,N M = M + X(I) 100 CONTINUE M = M / N V = 0 DO 200 I=1,N V = V + (X(I)-M)**2 200 CONTINUE VAR1 = V/N RETURN END C REAL*4 FUNCTION VAR2(N,X) INTEGER*4 N REAL*4 X(*) INTEGER*4 I REAL*4 S1,S2 S1 = 0 S2 = 0 DO 100 I=1,N S1 = S1 + X(I) S2 = S2 + X(I)**2 100 CONTINUE VAR2 = (S2 - S1**2/N)/N RETURN END > Many attempts to use FP for which 15 digits aren't enough should never > have been done in floating point to begin with. Calculations with money > are the classic example: FP trades off precision for total range. > Monetary calculations need high precision, and relatively little total > range; you'll never get correct results for monetary calculations in > floating point. I absolutely agree with you, but I would explain the same in a different way. Money is per nature not floating point, they are fixed point (integers with an embedded decimal point). > If you really need more precision, VAXes have H_FLOAT, a quadruple > precision format (with, as I recall, somewhere over 115 bits of > precision). However, it's emulated on all but some very, very old VAXes > - there simply wasn't enough demand to justify it, except for rare and > unusual algorithms. Alphas have no hardware support for H_FLOAT, though On Alpha you have X-floating in software emulation (X-floating is a REAL*16 IEEE floating point format. They are supported in Fortran. I am not quite sure about other languages. Arne