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 double precision x( n ), r, answerc,
64 $ answerd, ainf, anan, reldiff, b,
65 $ eps, bluemin, bluemax, xj, stepx(n), limx(n)
66 double complex y, cinf( ninf ), cnan( nnan )
69 intrinsic abs, dble, radix, ceiling, tiny, digits, sqrt,
70 $ maxexponent, minexponent, floor, huge, dcmplx,
75 subnormaltreatedas0 = 0
82 min = minexponent(0.0d0)
83 max = maxexponent(0.0d0)
85 b = dble(radix(0.0d0))
87 bluemin = b**ceiling( (min - 1) * 0.5d0 )
88 bluemax = b**floor( (max - m + 1) * 0.5d0 )
91 x(1) = tiny(0.0d0) * b**( dble(1-m) )
94 x(4) = b**( dble(max-1) )
110 cinf(1) = dcmplx( ainf, 0.0d0 )
111 cinf(2) = dcmplx(-ainf, 0.0d0 )
112 cinf(3) = dcmplx( 0.0d0, ainf )
113 cinf(4) = dcmplx( 0.0d0,-ainf )
114 cinf(5) = dcmplx( ainf, ainf )
118 cnan(1) = dcmplx( anan, 0.0d0 )
119 cnan(2) = dcmplx( 0.0d0, anan )
120 cnan(3) = dcmplx( anan, anan )
127 print *,
'# Blue min constant :=', bluemin
128 print *,
'# Blue max constant :=', bluemax
132 if( xj .eq. 0.0d0 )
then
133 subnormaltreatedas0 = subnormaltreatedas0 + 1
134 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
135 print *,
"!! fl( subnormal ) may be 0"
140 if( xj .eq. 0.0d0 )
then
141 subnormaltreatedas0 = subnormaltreatedas0 + 1
142 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
143 print *,
"!! fl( subnormal ) may be 0"
152 if( xj .eq. 0.0d0 )
then
153 subnormaltreatedas0 = subnormaltreatedas0 + 1
154 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
155 print *,
"!! [a] fl( subnormal ) may be 0"
158 do while( xj .ne. limx(i) )
159 y = dcmplx( xj, 0.0d0 )
162 caseafails = caseafails + 1
163 if( caseafails .eq. 1 )
then
164 print *,
"!! Some ABS(x+0*I) differ from ABS(x)"
166 WRITE( 0, fmt = 9999 )
'a',i, xj,
'(1+0*I)', r, xj
176 if( xj .eq. 0.0d0 )
then
177 subnormaltreatedas0 = subnormaltreatedas0 + 1
178 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
179 print *,
"!! [b] fl( subnormal ) may be 0"
182 do while( xj .ne. limx(i) )
183 y = dcmplx( 0.0d0, xj )
186 casebfails = casebfails + 1
187 if( casebfails .eq. 1 )
then
188 print *,
"!! Some ABS(0+x*I) differ from ABS(x)"
190 WRITE( 0, fmt = 9999 )
'b',i, xj,
'(0+1*I)', r, xj
199 if( i .eq. 3 )
go to 30
205 if( xj .eq. 0.0d0 )
then
206 subnormaltreatedas0 = subnormaltreatedas0 + 1
207 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
208 print *,
"!! [c] fl( subnormal ) may be 0"
211 do while( xj .ne. limx(i) )
212 answerc = fivefourth * xj
213 y = dcmplx( threefourth * xj, xj )
215 if( r .ne. answerc )
then
216 casecfails = casecfails + 1
217 if( casecfails .eq. 1 )
then
219 $
"!! Some ABS(x*(3/4+I)) differ from (5/4)*ABS(x)"
221 WRITE( 0, fmt = 9999 )
'c',i, xj,
'(3/4+I)', r,
236 if( xj .eq. 0.0d0 )
then
237 subnormaltreatedas0 = subnormaltreatedas0 + 1
238 if( debug .or. subnormaltreatedas0 .eq. 1 )
then
239 print *,
"!! [d] fl( subnormal ) may be 0"
242 do while( xj .ne. limx(i) )
243 answerd = (onehalf * xj) * sqrt(2.0d0)
244 if( answerd .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 y = dcmplx( onehalf * xj, onehalf * xj )
252 reldiff = abs(r-answerd)/answerd
253 if( reldiff .ge. (0.5*eps) )
then
254 casedfails = casedfails + 1
255 if( casedfails .eq. 1 )
then
257 $
"!! Some ABS(x*(1+I)) differ from sqrt(2)*ABS(x)"
259 WRITE( 0, fmt = 9999 )
'd',i, (onehalf*xj),
260 $
'(1+1*I)', r, answerd
272 if( .not.(r .gt. huge(0.0d0)) )
then
273 WRITE( *, fmt = 9997 )
'i',i, y, r
282 WRITE( *, fmt = 9998 )
'n',i, y, r
287 if( (caseafails .gt. 0) .or. (casebfails .gt. 0) .or.
288 $ (casecfails .gt. 0) .or. (casedfails .gt. 0) )
289 $ print *,
"# Please check the failed ABS(a+b*I) in [stderr]"
292 9997
FORMAT(
'[',a1,i1,
'] ABS(', (es8.1,sp,es8.1,
"*I"),
' ) = ',
293 $ es8.1,
' differs from Inf' )
295 9998
FORMAT(
'[',a1,i1,
'] ABS(', (es8.1,sp,es8.1,
"*I"),
' ) = ',
296 $ es8.1,
' differs from NaN' )
298 9999
FORMAT(
'[',a1,i1,
'] ABS(', es24.16e3,
' * ', a7,
' ) = ',
299 $ es24.16e3,
' differs from ', es24.16e3 )
program zabs
zabs tests the robustness and precision of the intrinsic ABS for double complex