2 c f90-intrinsic-numeric.f
4 c Test Fortran 90 intrinsic numeric functions - Section 13.10.2 and 13.13
5 c David Billinghurst <David.Billinghurst@riotinto.com>
8 c * g77 does not fully comply with F90. Noncompliances noted in comments.
9 c * Section 13.12: Specific names for intrinsic functions tested in
13 integer(kind=2) j, j2, ja
14 integer(kind=1) k, k2, ka
19 c ABS - Section 13.13.1
24 call c_i(ABS(-7),7,'ABS(integer)')
25 call c_i2(ABS(j),ja,'ABS(integer(2))')
26 call c_i1(ABS(k),ka,'ABS(integer(1))')
27 call c_r(ABS(-7.),7.,'ABS(real)')
28 call c_d(ABS(-7.d0),7.d0,'ABS(double)')
29 call c_r(ABS((3.,-4.)),5.0,'ABS(complex)')
30 call c_d(ABS((3.d0,-4.d0)),5.0d0,'ABS(complex(kind=8))')
32 c AIMAG - Section 13.13.6
33 call c_r(AIMAG((2.,-7.)),-7.,'AIMAG(complex)')
34 c g77: AIMAG(complex(kind=8)) does not comply with F90
35 c call c_d(AIMAG((2.d0,-7.d0)),-7.d0,'AIMAG(complex(kind=8))')
37 c AINT - Section 13.13.7
38 call c_r(AINT(2.783),2.0,'AINT(real) 1')
39 call c_r(AINT(-2.783),-2.0,'AINT(real) 2')
40 call c_d(AINT(2.783d0),2.0d0,'AINT(double precision) 1')
41 call c_d(AINT(-2.783d0),-2.0d0,'AINT(double precision) 2')
42 c Note: g77 does not support optional argument KIND
44 c ANINT - Section 13.13.10
45 call c_r(ANINT(2.783),3.0,'ANINT(real) 1')
46 call c_r(ANINT(-2.783),-3.0,'ANINT(real) 2')
47 call c_d(ANINT(2.783d0),3.0d0,'ANINT(double precision) 1')
48 call c_d(ANINT(-2.783d0),-3.0d0,'ANINT(double precision) 2')
49 c Note: g77 does not support optional argument KIND
51 c CEILING - Section 13.13.18
54 c CMPLX - Section 13.13.20
59 call c_c(CMPLX(1),(1.,0.),'CMPLX(integer)')
60 call c_c(CMPLX(1,2),(1.,2.),'CMPLX(integer, integer)')
61 call c_c(CMPLX(j),(1.,0.),'CMPLX(integer(2))')
62 call c_c(CMPLX(j,ja),(1.,2.),'CMPLX(integer(2), integer(2))')
63 call c_c(CMPLX(k),(1.,0.),'CMPLX(integer(1)')
64 call c_c(CMPLX(k,ka),(1.,2.),'CMPLX(integer(1), integer(1))')
65 call c_c(CMPLX(1.),(1.,0.),'CMPLX(real)')
66 call c_c(CMPLX(1.d0),(1.,0.),'CMPLX(double)')
67 call c_c(CMPLX(1.d0,2.d0),(1.,2.),'CMPLX(double,double)')
68 call c_c(CMPLX(1.,2.),(1.,2.),'CMPLX(complex)')
69 call c_c(CMPLX(1.d0,2.d0),(1.,2.),'CMPLX(complex(kind=8))')
70 c NOTE: g77 does not support optional argument KIND
72 c CONJG - Section 13.13.21
73 call c_c(CONJG((2.,-7.)),(2.,7.),'CONJG(complex)')
74 call c_z(CONJG((2.d0,-7.d0)),(2.d0,7.d0),'CONJG(complex(kind=8))')
76 c DBLE - Section 13.13.27
79 call c_d(DBLE(5),5.0d0,'DBLE(integer)')
80 call c_d(DBLE(j),5.0d0,'DBLE(integer(2))')
81 call c_d(DBLE(k),5.0d0,'DBLE(integer(1))')
82 call c_d(DBLE(5.),5.0d0,'DBLE(real)')
83 call c_d(DBLE(5.0d0),5.0d0,'DBLE(double)')
84 call c_d(DBLE((5.0,0.5)),5.0d0,'DBLE(complex)')
85 call c_d(DBLE((5.0d0,0.5d0)),5.0d0,'DBLE(complex(kind=8))')
87 c DIM - Section 13.13.29
94 call c_i(DIM(-8,-3),0,'DIM(integer)')
95 call c_i2(DIM(j,j2),ja,'DIM(integer(2))')
96 call c_i1(DIM(k,k2),ka,'DIM(integer(1)')
97 call c_r(DIM(-8.,-3.),0.,'DIM(real,real)')
98 call c_d(DIM(-8.d0,-3.d0),0.d0,'DIM(double,double)')
100 c DPROD - Section 13.13.31
101 call c_d(DPROD(-8.,-3.),24.d0,'DPROD(real,real)')
103 c FLOOR - Section 13.13.36
106 c INT - Section 13.13.47
109 call c_i(INT(5),5,'INT(integer)')
110 call c_i(INT(j),5,'INT(integer(2))')
111 call c_i(INT(k),5,'INT(integer(1))')
112 call c_i(INT(5.01),5,'INT(real)')
113 call c_i(INT(5.01d0),5,'INT(double)')
114 c Note: Does not accept optional second argument KIND
116 c MAX - Section 13.13.63
123 call c_i(MAX(1,2,3),3,'MAX(integer,integer,integer)')
124 call c_i2(MAX(j,j2),ja,'MAX(integer(2),integer(2))')
125 call c_i1(MAX(k,k2),ka,'MAX(integer(1),integer(1))')
126 call c_r(MAX(1.,2.,3.),3.,'MAX(real,real,real)')
127 call c_d(MAX(1.d0,2.d0,3.d0),3.d0,'MAX(double,double,double)')
129 c MIN - Section 13.13.68
136 call c_i(MIN(1,2,3),1,'MIN(integer,integer,integer)')
137 call c_i2(MIN(j,j2),ja,'MIN(integer(2),integer(2))')
138 call c_i1(MIN(k,k2),ka,'MIN(integer(1),integer(1))')
139 call c_r(MIN(1.,2.,3.),1.,'MIN(real,real,real)')
140 call c_d(MIN(1.d0,2.d0,3.d0),1.d0,'MIN(double,double,double)')
142 c MOD - Section 13.13.72
143 call c_i(MOD(8,5),3,'MOD(integer,integer) 1')
144 call c_i(MOD(-8,5),-3,'MOD(integer,integer) 2')
145 call c_i(MOD(8,-5),3,'MOD(integer,integer) 3')
146 call c_i(MOD(-8,-5),-3,'MOD(integer,integer) 4')
150 call c_i2(MOD(j,j2),ja,'MOD(integer(2),integer(2)) 1')
151 call c_i2(MOD(-j,j2),-ja,'MOD(integer(2),integer(2)) 2')
152 call c_i2(MOD(j,-j2),ja,'MOD(integer(2),integer(2)) 3')
153 call c_i2(MOD(-j,-j2),-ja,'MOD(integer(2),integer(2)) 4')
157 call c_i1(MOD(k,k2),ka,'MOD(integer(1),integer(1)) 1')
158 call c_i1(MOD(-k,k2),-ka,'MOD(integer(1),integer(1)) 2')
159 call c_i1(MOD(k,-k2),ka,'MOD(integer(1),integer(1)) 3')
160 call c_i1(MOD(-k,-k2),-ka,'MOD(integer(1),integer(1)) 4')
161 call c_r(MOD(8.,5.),3.,'MOD(real,real) 1')
162 call c_r(MOD(-8.,5.),-3.,'MOD(real,real) 2')
163 call c_r(MOD(8.,-5.),3.,'MOD(real,real) 3')
164 call c_r(MOD(-8.,-5.),-3.,'MOD(real,real) 4')
165 call c_d(MOD(8.d0,5.d0),3.d0,'MOD(double,double) 1')
166 call c_d(MOD(-8.d0,5.d0),-3.d0,'MOD(double,double) 2')
167 call c_d(MOD(8.d0,-5.d0),3.d0,'MOD(double,double) 3')
168 call c_d(MOD(-8.d0,-5.d0),-3.d0,'MOD(double,double) 4')
170 c MODULO - Section 13.13.73
173 c NINT - Section 13.13.76
174 call c_i(NINT(2.783),3,'NINT(real)')
175 call c_i(NINT(2.783d0),3,'NINT(double)')
176 c Optional second argument KIND not implemented
178 c REAL - Section 13.13.86
181 call c_r(REAL(-2),-2.0,'REAL(integer)')
182 call c_r(REAL(j),-2.0,'REAL(integer(2))')
183 call c_r(REAL(k),-2.0,'REAL(integer(1))')
184 call c_r(REAL(-2.0),-2.0,'REAL(real)')
185 call c_r(REAL(-2.0d0),-2.0,'REAL(double)')
186 call c_r(REAL((-2.,9.)),-2.0,'REAL(complex)')
187 c REAL(complex(kind=8)) not implemented
188 c call c_r(REAL((-2.d0,9.d0)),-2.0,'REAL(complex(kind=8))')
190 c SIGN - Section 13.13.96
197 call c_i(SIGN(-3,2),3,'SIGN(integer)')
198 call c_i2(SIGN(j,j2),ja,'SIGN(integer(2))')
199 call c_i1(SIGN(k,k2),ka,'SIGN(integer(1))')
200 call c_r(SIGN(-3.0,2.),3.,'SIGN(real,real)')
201 call c_d(SIGN(-3.d0,2.d0),3.d0,'SIGN(double,double)')
203 if ( fail ) call abort()
206 subroutine failure(label)
207 c Report failure and set flag
211 write(6,'(a,a,a)') 'Test ',label,' FAILED'
215 subroutine c_i(i,j,label)
216 c Check if INTEGER i equals j, and fail otherwise
221 write(6,*) 'Got ',i,' expected ', j
225 subroutine c_i2(i,j,label)
226 c Check if INTEGER(kind=2) i equals j, and fail otherwise
231 write(6,*) 'Got ',i,' expected ', j
235 subroutine c_i1(i,j,label)
236 c Check if INTEGER(kind=1) i equals j, and fail otherwise
241 write(6,*) 'Got ',i,' expected ', j
245 subroutine c_r(a,b,label)
246 c Check if REAL a equals b, and fail otherwise
249 if ( abs(a-b) .gt. 1.0e-5 ) then
251 write(6,*) 'Got ',a,' expected ', b
255 subroutine c_d(a,b,label)
256 c Check if DOUBLE PRECISION a equals b, and fail otherwise
257 double precision a, b
259 if ( abs(a-b) .gt. 1.0d-5 ) then
261 write(6,*) 'Got ',a,' expected ', b
265 subroutine c_c(a,b,label)
266 c Check if COMPLEX a equals b, and fail otherwise
269 if ( abs(a-b) .gt. 1.0e-5 ) then
271 write(6,*) 'Got ',a,' expected ', b
275 subroutine c_z(a,b,label)
276 c Check if COMPLEX a equals b, and fail otherwise
279 if ( abs(a-b) .gt. 1.0d-5 ) then
281 write(6,*) 'Got ',a,' expected ', b