65 parameter( debug = .false. )
67 parameter( n = 4, nnan = 3, ninf = 5 )
68 double precision threefourth, fivefourth
69 parameter( threefourth = 3.0d0 / 4,
70 $ fivefourth = 5.0d0 / 4 )
71 double complex czero, cone
72 parameter( czero = dcmplx( 0.0d0, 0.0d0 ),
73 $ cone = dcmplx( 1.0d0, 0.0d0 ) )
76 integer i, min, max, m,
77 $ subnormaltreatedas0, caseafails, casebfails,
78 $ casecfails, casedfails, caseefails, caseffails,
79 $ caseinffails, casenanfails, nfailingtests,
81 double precision x( n ), ainf, anan, b,
82 $ eps, bluemin, bluemax, ov, xj, stepx(n), limx(n)
83 double complex y, y2, r, cinf( ninf ), cnan( nnan )
86 intrinsic dconjg, dble, radix, ceiling, tiny, digits,
87 $ maxexponent, minexponent, floor, huge, dcmplx,
92 subnormaltreatedas0 = 0
105 min = minexponent(0.0d0)
106 max = maxexponent(0.0d0)
108 b = dble(radix(0.0d0))
110 bluemin = b**ceiling( (min - 1) * 0.5d0 )
111 bluemax = b**floor( (max - m + 1) * 0.5d0 )
115 x(1) = tiny(0.0d0) * b**( dble(1-m) )
118 x(4) = b**( dble(max-1) )
134 cinf(1) = dcmplx( ainf, 0.0d0 )
135 cinf(2) = dcmplx(-ainf, 0.0d0 )
136 cinf(3) = dcmplx( 0.0d0, ainf )
137 cinf(4) = dcmplx( 0.0d0,-ainf )
138 cinf(5) = dcmplx( ainf, ainf )
142 cnan(1) = dcmplx( anan, 0.0d0 )
143 cnan(2) = dcmplx( 0.0d0, anan )
144 cnan(3) = dcmplx( anan, anan )
151 print *,
'# Blue min constant :=', bluemin
152 print *,
'# Blue max constant :=', bluemax
156 if( xj .eq. 0.0d0 )
then
157 subnormaltreatedas0 = subnormaltreatedas0 + 1
158 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
159 print *,
"!! fl( subnormal ) may be 0"
164 if( xj .eq. 0.0d0 )
then
165 subnormaltreatedas0 = subnormaltreatedas0 + 1
166 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
167 print *,
"!! fl( subnormal ) may be 0"
176 if( xj .eq. 0.0d0 )
then
177 subnormaltreatedas0 = subnormaltreatedas0 + 1
178 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
179 print *,
"!! [a] fl( subnormal ) may be 0"
182 do while( xj .ne. limx(i) )
184 y = dcmplx( xj, 0.0d0 )
186 if( r .ne. 1.0d0 )
then
187 caseafails = caseafails + 1
188 if( caseafails .eq. 1 )
then
189 print *,
"!! Some (x+0*I)/(x+0*I) differ from 1"
191 WRITE( 0, fmt = 9999 )
'a',i, xj,
192 $
'(x+0*I)/(x+0*I)', r, 1.0d0
202 if( xj .eq. 0.0d0 )
then
203 subnormaltreatedas0 = subnormaltreatedas0 + 1
204 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
205 print *,
"!! [b] fl( subnormal ) may be 0"
208 do while( xj .ne. limx(i) )
210 y = dcmplx( 0.0d0, xj )
212 if( r .ne. 1.0d0 )
then
213 casebfails = casebfails + 1
214 if( casebfails .eq. 1 )
then
215 print *,
"!! Some (0+x*I)/(0+x*I) differ from 1"
217 WRITE( 0, fmt = 9999 )
'b',i, xj,
218 $
'(0+x*I)/(0+x*I)', r, 1.0d0
228 if( xj .eq. 0.0d0 )
then
229 subnormaltreatedas0 = subnormaltreatedas0 + 1
230 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
231 print *,
"!! [c] fl( subnormal ) may be 0"
234 do while( xj .ne. limx(i) )
238 if( r .ne. 1.0d0 )
then
239 casecfails = casecfails + 1
240 if( casecfails .eq. 1 )
then
241 print *,
"!! Some (x+x*I)/(x+x*I) differ from 1"
243 WRITE( 0, fmt = 9999 )
'c',i, xj,
244 $
'(x+x*I)/(x+x*I)', r, 1.0d0
254 if( xj .eq. 0.0d0 )
then
255 subnormaltreatedas0 = subnormaltreatedas0 + 1
256 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
257 print *,
"!! [d] fl( subnormal ) may be 0"
260 do while( xj .ne. limx(i) )
262 y = dcmplx( 0.0d0, xj )
263 y2 = dcmplx( xj, 0.0d0 )
265 if( r .ne. dcmplx(0.0d0,1.0d0) )
then
266 casedfails = casedfails + 1
267 if( casedfails .eq. 1 )
then
268 print *,
"!! Some (0+x*I)/(x+0*I) differ from I"
270 WRITE( 0, fmt = 9999 )
'd',i, xj,
'(0+x*I)/(x+0*I)',
271 $ r, dcmplx(0.0d0,1.0d0)
281 if( xj .eq. 0.0d0 )
then
282 subnormaltreatedas0 = subnormaltreatedas0 + 1
283 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
284 print *,
"!! [e] fl( subnormal ) may be 0"
287 do while( xj .ne. limx(i) )
289 y = dcmplx( 0.0d0, xj )
290 y2 = dcmplx( xj, 0.0d0 )
292 if( r .ne. dcmplx(0.0d0,-1.0d0) )
then
293 caseefails = caseefails + 1
294 if( caseefails .eq. 1 )
then
295 print *,
"!! Some (x+0*I)/(0+x*I) differ from -I"
297 WRITE( 0, fmt = 9999 )
'e',i, xj,
'(x+0*I)/(0+x*I)',
298 $ r, dcmplx(0.0d0,-1.0d0)
308 if( xj .eq. 0.0d0 )
then
309 subnormaltreatedas0 = subnormaltreatedas0 + 1
310 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
311 print *,
"!! [f] fl( subnormal ) may be 0"
314 do while( xj .ne. limx(i) )
318 if( r .ne. dcmplx(0.0d0,1.0d0) )
then
319 caseffails = caseffails + 1
320 if( caseffails .eq. 1 )
then
321 print *,
"!! Some (x+x*I)/(x-x*I) differ from I"
323 WRITE( 0, fmt = 9999 )
'f',i, xj,
'(x+x*I)/(x-x*I)',
324 $ r, dcmplx(0.0d0,1.0d0)
336 if( (r .ne. czero) .and. (r .eq. r) )
then
337 caseinffails = caseinffails + 1
338 WRITE( *, fmt = 9998 )
'ia',i, czero, y, r,
'NaN and 0'
341 if( (r .ne. czero) .and. (r .eq. r) )
then
342 caseinffails = caseinffails + 1
343 WRITE( *, fmt = 9998 )
'ib',i, cone, y, r,
'NaN and 0'
347 caseinffails = caseinffails + 1
348 WRITE( *, fmt = 9998 )
'ic',i, y, y, r,
'NaN'
358 casenanfails = casenanfails + 1
359 WRITE( *, fmt = 9998 )
'na',i, czero, y, r,
'NaN'
363 casenanfails = casenanfails + 1
364 WRITE( *, fmt = 9998 )
'nb',i, cone, y, r,
'NaN'
368 casenanfails = casenanfails + 1
369 WRITE( *, fmt = 9998 )
'nc',i, y, y, r,
'NaN'
374 nfailingtests = caseafails + casebfails + casecfails + casedfails
375 $ + caseefails + caseffails + caseinffails
377 if( nfailingtests .gt. 0 )
then
378 print *,
"# ", ntests-nfailingtests,
" tests out of ", ntests,
379 $
" pass for complex division,", nfailingtests,
" fail."
381 print *,
"# All tests pass for complex division."
385 if( (caseafails .gt. 0) .or. (casebfails .gt. 0) .or.
386 $ (casecfails .gt. 0) .or. (casedfails .gt. 0) .or.
387 $ (caseefails .gt. 0) .or. (caseffails .gt. 0) )
388 $ print *,
"# Please check the failed divisions in [stderr]"
391 9998
FORMAT(
'[',a2,i1,
'] ', (es24.16e3,sp,es24.16e3,
"*I"),
' * ',
392 $ (es24.16e3,sp,es24.16e3,
"*I"),
' = ',
393 $ (es24.16e3,sp,es24.16e3,
"*I"),
' differs from ', a10 )
395 9999
FORMAT(
'[',a2,i1,
'] X = ', es24.16e3,
' : ', a15,
' = ',
396 $ (es24.16e3,sp,es24.16e3,
"*I"),
' differs from ',
397 $ (es24.16e3,sp,es24.16e3,
"*I") )
program zdiv
zdiv tests the robustness and precision of the double complex division