/* Program that is replacement for finite() Description This function checks if a number is finite. It determines if the passed floating point number represents an overflow condition. If the exponent of an AS/400 double (which is 8 byte) is all 1's and fraction is all 0's then it is infinite. Bits in an AS/400 double are: 0 sign 1:11 exponent 12:63 fraction Bit 0 is the leftmost bit. Choose your browser's option to 'save to local disk' and then reload this document to download this code example. Send the program to your AS/400 and compile it using the development facilities supplied there. This program was developed on a V3R6 system and tested on V3R1, V3R2 and V3R6 systems. This small program that is furnished by IBM is a simple example to provide an illustration. This example has not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of this program. All programs contained herein are provided to you "AS IS". THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. */ /************************************************************************/ /* */ /* test case: finite.c */ /* */ /* objective: finite() workaround */ /* */ /* usage notes: Compile this program using CRTCMOD and then bind the */ /* module with other modules using finite() to create */ /* program object. */ /* */ /************************************************************************/ #include typedef struct { unsigned long lobits; unsigned long hibits; } BITMASK; typedef union { BITMASK bm; double dv; } OVERLAY; #define EXPBITS 0x7FF00000 #define ALLZEROS 0x00000000 #define CHKEXP 0x000FFFFF int finite( double fres ) { OVERLAY value; value.dv = fres; if ( ( (value.bm.lobits & EXPBITS) == EXPBITS ) && ( (value.bm.lobits & CHKEXP) == ALLZEROS ) && ( value.bm.hibits == ALLZEROS ) ) return( 0 ); /* No, it is not a finite number */ else return( 1 ); /* it is a finite number */ }