NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
q9ie32.f
Go to the documentation of this file.
1C> @file
2C> @brief Convert IBM370 F.P. to IEEE F.P.
3C> @author Ralph Jones @date 1990-06-04
4
5C> Convert ibm370 32 bit floating point numbers to ieee
6C> 32 bit task 754 floating point numbers.
7C>
8C> Program history log:
9C> - Ralph Jones 1990-06-04 Change to sun fortran 1.3
10C> - Ralph Jones 1990-07-14 Change ishft to lshift or lrshft
11C> - Ralph Jones 1991-03-09 Change to silicongraphics fortran
12C> - Ralph Jones 1992-07-20 Change to ibm aix xl fortran
13C> - Ralph Jones 1995-11-15 Add save statement
14C> - Stephen Gilbert 1998-11-15 Specified 4-byte integers for IBM SP
15C>
16C> @param[in] A REAL*4 Array of ibm370 32 bit floating point numbers.
17C> @param[out] N Number of points to convert.
18C> @param[out] B REAL*4 Array of ieee 32 bit floating point numbers.
19C> @param[out] ISTAT Number of point greater than 10e+38, numbers are set to
20c> ieee infinity, one is added to istat. Numbers less than
21c> e-38 are set to zero, one is not added to istat.
22C>
23C> @note See ieee task 754 standard floating point arithmetic
24C> for more information about IEEE F.P.
25C>
26C> @author Ralph Jones @date 1990-06-04
27 SUBROUTINE q9ie32(A,B,N,ISTAT)
28C
29 INTEGER(4) A(*)
30 INTEGER(4) B(*)
31 INTEGER(4) SIGN
32 INTEGER(4) INFIN,MASKFR,MASKSN,MASK21,MASK22,MASK23
33 INTEGER(4) ITEMP,ISIGN,IEEEXP,K,LTEMP
34C
35 SAVE
36C
37 DATA infin /z'7F800000'/
38 DATA maskfr/z'007FFFFF'/
39 DATA masksn/z'7FFFFFFF'/
40 DATA mask21/z'00200000'/
41 DATA mask22/z'00400000'/
42 DATA mask23/z'00800000'/
43 DATA sign /z'80000000'/
44C
45 IF (n.LT.1) THEN
46 istat = -1
47 RETURN
48 ENDIF
49C
50 istat = 0
51C
52 DO 40 i = 1,n
53 isign = 0
54 itemp = a(i)
55C
56C TEST SIGN BIT
57C
58 IF (itemp.EQ.0) GO TO 30
59C
60 IF (itemp.LT.0) THEN
61C
62 isign = sign
63C
64C SET SIGN BIT TO ZERO
65C
66 itemp = iand(itemp,masksn)
67C
68 END IF
69C
70C
71C CONVERT IBM EXPONENT TO IEEE EXPONENT
72C
73 ieeexp = (ishft(itemp,-24_4) - 64_4) * 4 + 126
74C
75 k = 0
76C
77C TEST BIT 23, 22, 21
78C ADD UP NUMBER OF ZERO BITS IN FRONT OF IBM370 FRACTION
79C
80 IF (iand(itemp,mask23).NE.0) GO TO 10
81 k = k + 1
82 IF (iand(itemp,mask22).NE.0) GO TO 10
83 k = k + 1
84 IF (iand(itemp,mask21).NE.0) GO TO 10
85 k = k + 1
86C
87 10 CONTINUE
88C
89C SUBTRACT ZERO BITS FROM EXPONENT
90C
91 ieeexp = ieeexp - k
92C
93C TEST FOR OVERFLOW
94C
95 IF (ieeexp.GT.254) GO TO 20
96C
97C TEST FOR UNDERFLOW
98C
99 IF (ieeexp.LT.1) GO TO 30
100C
101C SHIFT IEEE EXPONENT TO BITS 1 TO 8
102C
103 ltemp = ishft(ieeexp,23_4)
104C
105C SHIFT IBM370 FRACTION LEFT K BIT, AND OUT BITS 0 - 8
106C OR TOGETHER THE EXPONENT AND THE FRACTION
107C OR IN SIGN BIT
108C
109 b(i) = ior(ior(iand(ishft(itemp,k),maskfr),ltemp),isign)
110C
111 GO TO 40
112C
113 20 CONTINUE
114C
115C OVERFLOW , SET TO IEEE INFINITY, ADD 1 TO OVERFLOW COUNTER
116C
117 istat = istat + 1
118 b(i) = ior(infin,isign)
119 GO TO 40
120C
121 30 CONTINUE
122C
123C UNDERFLOW , SET TO ZERO
124C
125 b(i) = 0
126C
127 40 CONTINUE
128C
129 RETURN
130 END
subroutine q9ie32(a, b, n, istat)
Convert ibm370 32 bit floating point numbers to ieee 32 bit task 754 floating point numbers.
Definition q9ie32.f:28