C$Procedure SIGBIT_1 ( Significant bits ) SUBROUTINE SIGBIT_1 ( DX, SCALE, NLBIT, NBITS ) C$ Abstract C C Compute the size of DX relative to the least significant bit C of SCALE. Also compute the number of significant bits that C this corresponds to in terms of SCALE. C C$ Required_Reading C C None. C C$ Keywords C C MATH C UTILITY C C$ Declarations DOUBLE PRECISION DX DOUBLE PRECISION SCALE INTEGER NLBIT INTEGER NBITS C$ Brief_I/O C C Variable I/O Description C -------- --- -------------------------------------------------- C DX I A small deviation in SCALE C SCALE I A reference double precision number C NLBIT O The size of DX interms of the l.s.b of SCALE C NBITS O The position of the most significant bit of DX. C C$ Detailed_Input C C DX is a number (expected to be less than SCALE) that C is to be compared with SCALE to determine its C size in terms of the least significant bit of SCALE. C C SCALE is a reference value, whose least significant bit C will be compared to DX. C C$ Detailed_Output C C NLBIT is nearest integer to DX divided by the least C significant bit of SCALE. C C NBITS is the number of bits required to represent NLBIT. C C$ Parameters C C None. C C$ Exceptions C C 1) If the absolute value of DX divided by the least significant C bit of SCALE cannot be computed as an integer, the routine C will simply return INTMAX. The assumption is that you don't C plan to do anything but display this number anyway. C C$ Files C C None. C C$ Particulars C C When comparing differences between two methods of computation, C it is often desirable to understand the difference in terms of C the least significant bit of the quantity being computed. C C This routine provides a simple mechanism for performing this C computation. C C The value, VAL, of the least significant bit of the number C SCALE is defined to be DPPREC_1()*SCALE. (Here, DPPREC_1 is the C smallest power of two that can be added to or subtracted from C 1.0d0 and produce a number other than 1.) C C The value returned in NLBIT is simply the integer closest to C DX/VAL. NBITS is the larger of 0 and the largest value of N C such that 2**N is less than or equal to NLBIT. C C$ Examples C C Suppose to wish to determine the number of bits represented by C a relative difference between two numbers S and T. Simply C exercise the code fragment shown below. C C CALL SIGBIT_1 ( DABS(X-Y), MAX(DABS(X),DABS(Y)), NLBIT, NBITS) C C WRITE (*,*) 'The relative difference is :', NLBIT, ' times '// C . 'the l.s.b. of the larger of X and Y'. C WRITE (*,*) 'This corresponds to approximately', NBITS, C . ' bits of precision. ' C C$ Restrictions C C None. C C$ Literature_References C C None. C C$ Author_and_Institution C C W.L. Taber (JPL) C C$ Version C C- Beta Version 1.0.0, 27-FEB-1992 (WLT) C C-& C$ Index_Entry C C 59 C 0........1.........2.........3.........4.........5........^ C C NUMBER OF SIGNIFICANT BITS OF ONE DP RELATIVE TO ANOTHER C C-& C C Entry points C C C SPICELIB functions C DOUBLE PRECISION BRCKTD DOUBLE PRECISION DPMAX INTEGER INTMAX C C Other functions C DOUBLE PRECISION DPPREC_1 C C Local variables C DOUBLE PRECISION VAL DOUBLE PRECISION DPINT DOUBLE PRECISION XBITS INTEGER MXBITS C C Initial values C VAL = DPPREC_1()*SCALE DPINT = INTMAX() MXBITS = NINT( DLOG(DPINT)/DLOG(2.0D0) + 1.0D0 ) C C Make sure we can actually perform the intended calculations. C IF ( DABS(VAL) .LT. 1.0D0 ) THEN IF ( ABS(DX) .GE. DPMAX()*ABS(VAL) ) THEN NLBIT = INTMAX() NBITS = MXBITS RETURN END IF END IF IF ( DX .EQ. 0 ) THEN NLBIT = 0 NBITS = 0 RETURN END IF C C Once we get this far, we know we are safe to compute C the ratio DX/VAL (no floating point overflows can occur). C XBITS = BRCKTD ( DX/VAL, -DPINT, DPINT ) NLBIT = NINT ( XBITS ) NLBIT = ABS ( NLBIT ) C C For the number of bits of precision, we only care about C the maginitude. C NBITS = NINT ( 1.0D0 . + ( DLOG(ABS(DX)) - DLOG(ABS(VAL)) )/DLOG(2.0D0)) NBITS = MAX ( NBITS, 0 ) RETURN END