52 parameter( debug = .false. )
54 parameter( n = 4, nnan = 3, ninf = 5 )
55 double precision threefourth, fivefourth, onehalf
56 parameter( threefourth = 3.0d0 / 4,
57 $ fivefourth = 5.0d0 / 4,
58 $ onehalf = 1.0d0 / 2 )
61 integer i, min, max, m, subnormaltreatedas0,
62 $ caseafails, casebfails, casecfails, casedfails,
63 $ caseefails, caseffails, nfailingtests, ntests
64 double precision x( n ), r, answerc,
65 $ answerd, ainf, anan, reldiff, b,
66 $ eps, bluemin, bluemax, xj, stepx(n), limx(n)
67 double complex y, cinf( ninf ), cnan( nnan )
70 intrinsic abs, dble, radix, ceiling, tiny, digits, sqrt,
71 $ maxexponent, minexponent, floor, huge, dcmplx,
76 subnormaltreatedas0 = 0
87 min = minexponent(0.0d0)
88 max = maxexponent(0.0d0)
90 b = dble(radix(0.0d0))
92 bluemin = b**ceiling( (min - 1) * 0.5d0 )
93 bluemax = b**floor( (max - m + 1) * 0.5d0 )
96 x(1) = tiny(0.0d0) * b**( dble(1-m) )
99 x(4) = b**( dble(max-1) )
115 cinf(1) = dcmplx( ainf, 0.0d0 )
116 cinf(2) = dcmplx(-ainf, 0.0d0 )
117 cinf(3) = dcmplx( 0.0d0, ainf )
118 cinf(4) = dcmplx( 0.0d0,-ainf )
119 cinf(5) = dcmplx( ainf, ainf )
123 cnan(1) = dcmplx( anan, 0.0d0 )
124 cnan(2) = dcmplx( 0.0d0, anan )
125 cnan(3) = dcmplx( anan, anan )
132 print *,
'# Blue min constant :=', bluemin
133 print *,
'# Blue max constant :=', bluemax
137 if( xj .eq. 0.0d0 )
then
138 subnormaltreatedas0 = subnormaltreatedas0 + 1
139 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
140 print *,
"!! fl( subnormal ) may be 0"
145 if( xj .eq. 0.0d0 )
then
146 subnormaltreatedas0 = subnormaltreatedas0 + 1
147 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
148 print *,
"!! fl( subnormal ) may be 0"
157 if( xj .eq. 0.0d0 )
then
158 subnormaltreatedas0 = subnormaltreatedas0 + 1
159 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
160 print *,
"!! [a] fl( subnormal ) may be 0"
163 do while( xj .ne. limx(i) )
165 y = dcmplx( xj, 0.0d0 )
168 caseafails = caseafails + 1
169 if( caseafails .eq. 1 )
then
170 print *,
"!! Some ABS(x+0*I) differ from ABS(x)"
172 WRITE( 0, fmt = 9999 )
'a',i, xj,
'(1+0*I)', r, xj
182 if( xj .eq. 0.0d0 )
then
183 subnormaltreatedas0 = subnormaltreatedas0 + 1
184 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
185 print *,
"!! [b] fl( subnormal ) may be 0"
188 do while( xj .ne. limx(i) )
190 y = dcmplx( 0.0d0, xj )
193 casebfails = casebfails + 1
194 if( casebfails .eq. 1 )
then
195 print *,
"!! Some ABS(0+x*I) differ from ABS(x)"
197 WRITE( 0, fmt = 9999 )
'b',i, xj,
'(0+1*I)', r, xj
206 if( i .eq. 3 )
go to 30
212 if( xj .eq. 0.0d0 )
then
213 subnormaltreatedas0 = subnormaltreatedas0 + 1
214 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
215 print *,
"!! [c] fl( subnormal ) may be 0"
218 do while( xj .ne. limx(i) )
220 answerc = fivefourth * xj
221 y = dcmplx( threefourth * xj, xj )
223 if( r .ne. answerc )
then
224 casecfails = casecfails + 1
225 if( casecfails .eq. 1 )
then
227 $
"!! Some ABS(x*(3/4+I)) differ from (5/4)*ABS(x)"
229 WRITE( 0, fmt = 9999 )
'c',i, xj,
'(3/4+I)', r,
244 if( xj .eq. 0.0d0 )
then
245 subnormaltreatedas0 = subnormaltreatedas0 + 1
246 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
247 print *,
"!! [d] fl( subnormal ) may be 0"
250 do while( xj .ne. limx(i) )
251 answerd = (onehalf * xj) * sqrt(2.0d0)
252 if( answerd .eq. 0.0d0 )
then
253 subnormaltreatedas0 = subnormaltreatedas0 + 1
254 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
255 print *,
"!! [d] fl( subnormal ) may be 0"
259 y = dcmplx( onehalf * xj, onehalf * xj )
261 reldiff = abs(r-answerd)/answerd
262 if( reldiff .ge. (0.5*eps) )
then
263 casedfails = casedfails + 1
264 if( casedfails .eq. 1 )
then
266 $
"!! Some ABS(x*(1+I)) differ from sqrt(2)*ABS(x)"
268 WRITE( 0, fmt = 9999 )
'd',i, (onehalf*xj),
269 $
'(1+1*I)', r, answerd
282 if( .not.(r .gt. huge(0.0d0)) )
then
283 caseefails = caseefails + 1
284 WRITE( *, fmt = 9997 )
'i',i, y, r
294 caseffails = caseffails + 1
295 WRITE( *, fmt = 9998 )
'n',i, y, r
300 nfailingtests = caseafails + casebfails + casecfails + casedfails
301 $ + caseefails + caseffails
302 if( nfailingtests .gt. 0 )
then
303 print *,
"# ", ntests-nfailingtests,
" tests out of ", ntests,
304 $
" pass for ABS(a+b*I),", nfailingtests,
" tests fail."
306 print *,
"# All tests pass for ABS(a+b*I)"
310 if( (caseafails .gt. 0) .or. (casebfails .gt. 0) .or.
311 $ (casecfails .gt. 0) .or. (casedfails .gt. 0) )
then
312 print *,
"# Please check the failed ABS(a+b*I) in [stderr]"
316 9997
FORMAT(
'[',a1,i1,
'] ABS(', (es8.1,sp,es8.1,
"*I"),
' ) = ',
317 $ es8.1,
' differs from Inf' )
319 9998
FORMAT(
'[',a1,i1,
'] ABS(', (es8.1,sp,es8.1,
"*I"),
' ) = ',
320 $ es8.1,
' differs from NaN' )
322 9999
FORMAT(
'[',a1,i1,
'] ABS(', es24.16e3,
' * ', a7,
' ) = ',
323 $ es24.16e3,
' differs from ', es24.16e3 )
program zabs
zabs tests the robustness and precision of the intrinsic ABS for double complex