From chemistry-request -8 at 8- ccl.net Tue Jun 25 19:47:50 1991 Date: Tue, 25 Jun 91 17:56:58 CDT From: twhitley*- at -*ncsa.uiuc.edu (Timothy A. Whitley) To: chemistry ^at^ ccl.net Subject: Epsilon Status: R Eric Stahlberg's code does one too many divide; the results of his code are too small by a factor of two. The test is for a "just noticeable difference" from 1.0, not a "too small to be noticed difference." I believe that it should go like this: PROGRAM MACHPR REAL*4 R4,TOL4,ZERO4 REAL*8 R8,TOL8,ZERO8 *MDC*IF IBM CRAY REAL*16 R16,TOL16,ZERO16 *MDC*ENDIF C ZERO4=0.0 ZERO8=0.0 R4=1.0 TOL4=R4 100 IF ((R4+TOL4).EQ.R4) GOTO 200 PRINT *,TOL4 TOL4=TOL4/2.0 GOTO 100 200 tol4 = tol4 * 2.0 PRINT *,'MACHINE PRECISION R4 IS GT :', TOL4 R8=1.0 TOL8=R8 300 IF ((R8+TOL8).EQ.R8) GOTO 400 PRINT *,TOL8 TOL8=TOL8/2.0 GOTO 300 400 tol8 = tol8 * 2.0 PRINT *,'MACHINE PRECISION R8 IS GT :', TOL8 *MDC*IF IBM CRAY R16=1.0 TOL16=R16 500 IF ((R16+TOL16).EQ.R16) GOTO 600 PRINT *,TOL16 TOL16=TOL16/2.0 GOTO 500 600 tol16 = tol16 * 2.0 PRINT *,'MACHINE PRECISION R16 IS GT :', TOL16 *MDC*ENDIF STOP END C code from one of the earlier pseudo-code examples looks like: main() { float eps = 0.00001; float y = 1.0; float x; Again: x = y + eps; /* find rough value of eps */ if (x > y) { eps = 0.5*eps; goto Again; } eps = 2.0*eps; Again1: x = y + eps; /* find value of eps within 1% */ if (x > y) { eps = 0.99*eps; goto Again1; } eps = eps/0.99; printf("%e",eps); } Under Cray UNICOS, there is also a /usr/include/float.h file which specifies the epsilon limits. =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= Tim Whitley (( Internet...twhitley _-at-_)ncsa.uiuc.edu Cray Research, Inc. )) Phone......(217) 244-4863 4139 Beckman Institute (( FAX........(217) 244-2909 405 N. Mathews Avenue )) "The views presented herein are not those Urbana, IL 61801 (( of Cray Research, but are solely my own." =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=