1c  f90-intrinsic-numeric.f
2c
3c Test Fortran 90 intrinsic numeric functions - Section 13.10.2 and 13.13
4c     David Billinghurst <David.Billinghurst@riotinto.com>
5c
6c Notes:
7c  * g77 does not fully comply with F90.  Noncompliances noted in comments.
8c  * Section 13.12: Specific names for intrinsic functions tested in
9c intrinsic77.f
10
11      logical fail
12      integer*2 j, j2, ja
13      integer*1 k, k2, ka
14
15      common /flags/ fail
16      fail = .false.
17
18c     ABS - Section 13.13.1
19      j = -9
20      ja = 9
21      k = j
22      ka = ja
23      call c_i(ABS(-7),7,'ABS(integer)')
24      call c_i2(ABS(j),ja,'ABS(integer*2)')
25      call c_i1(ABS(k),ka,'ABS(integer*1)')
26      call c_r(ABS(-7.),7.,'ABS(real)')
27      call c_d(ABS(-7.d0),7.d0,'ABS(double)')
28      call c_r(ABS((3.,-4.)),5.0,'ABS(complex)')
29      call c_d(ABS((3.d0,-4.d0)),5.0d0,'ABS(double complex)')
30
31c     AIMAG - Section 13.13.6
32      call c_r(AIMAG((2.,-7.)),-7.,'AIMAG(complex)')
33c     g77: AIMAG(double complex) does not comply with F90
34c     call c_d(AIMAG((2.d0,-7.d0)),-7.d0,'AIMAG(double complex)')
35
36c     AINT - Section 13.13.7
37      call c_r(AINT(2.783),2.0,'AINT(real) 1')
38      call c_r(AINT(-2.783),-2.0,'AINT(real) 2')
39      call c_d(AINT(2.783d0),2.0d0,'AINT(double precision) 1')
40      call c_d(AINT(-2.783d0),-2.0d0,'AINT(double precision) 2')
41c     Note:  g77 does not support optional argument KIND
42
43c     ANINT - Section 13.13.10
44      call c_r(ANINT(2.783),3.0,'ANINT(real) 1')
45      call c_r(ANINT(-2.783),-3.0,'ANINT(real) 2')
46      call c_d(ANINT(2.783d0),3.0d0,'ANINT(double precision) 1')
47      call c_d(ANINT(-2.783d0),-3.0d0,'ANINT(double precision) 2')
48c     Note:  g77 does not support optional argument KIND
49
50c     CEILING - Section 13.13.18
51c     Not implemented
52
53c     CMPLX - Section 13.13.20
54      j = 1
55      ja = 2
56      k = 1
57      ka = 2
58      call c_c(CMPLX(1),(1.,0.),'CMPLX(integer)')
59      call c_c(CMPLX(1,2),(1.,2.),'CMPLX(integer, integer)')
60      call c_c(CMPLX(j),(1.,0.),'CMPLX(integer*2)')
61      call c_c(CMPLX(j,ja),(1.,2.),'CMPLX(integer*2, integer*2)')
62      call c_c(CMPLX(k),(1.,0.),'CMPLX(integer*1)')
63      call c_c(CMPLX(k,ka),(1.,2.),'CMPLX(integer*1, integer*1)')
64      call c_c(CMPLX(1.),(1.,0.),'CMPLX(real)')
65      call c_c(CMPLX(1.d0),(1.,0.),'CMPLX(double)')
66      call c_c(CMPLX(1.d0,2.d0),(1.,2.),'CMPLX(double,double)')
67      call c_c(CMPLX(1.,2.),(1.,2.),'CMPLX(complex)')
68      call c_c(CMPLX(1.d0,2.d0),(1.,2.),'CMPLX(double complex)')
69c     NOTE: g77 does not support optional argument KIND
70
71c     CONJG - Section 13.13.21
72      call c_c(CONJG((2.,-7.)),(2.,7.),'CONJG(complex)')
73      call c_z(CONJG((2.d0,-7.d0)),(2.d0,7.d0),'CONJG(double complex)')
74
75c     DBLE - Section 13.13.27
76      j = 5
77      k = 5
78      call c_d(DBLE(5),5.0d0,'DBLE(integer)')
79      call c_d(DBLE(j),5.0d0,'DBLE(integer*2)')
80      call c_d(DBLE(k),5.0d0,'DBLE(integer*1)')
81      call c_d(DBLE(5.),5.0d0,'DBLE(real)')
82      call c_d(DBLE(5.0d0),5.0d0,'DBLE(double)')
83      call c_d(DBLE((5.0,0.5)),5.0d0,'DBLE(complex)')
84      call c_d(DBLE((5.0d0,0.5d0)),5.0d0,'DBLE(double complex)')
85
86c     DIM - Section 13.13.29
87      j = -8
88      j2 = -3
89      ja = 0
90      k = -8
91      k2 = -3
92      ka = 0
93      call c_i(DIM(-8,-3),0,'DIM(integer)')
94      call c_i2(DIM(j,j2),ja,'DIM(integer*2)')
95      call c_i1(DIM(k,k2),ka,'DIM(integer*1)')
96      call c_r(DIM(-8.,-3.),0.,'DIM(real,real)')
97      call c_d(DIM(-8.d0,-3.d0),0.d0,'DIM(double,double)')
98
99c     DPROD - Section 13.13.31
100      call c_d(DPROD(-8.,-3.),24.d0,'DPROD(real,real)')
101
102c     FLOOR - Section 13.13.36
103c     Not implemented
104
105c     INT - Section 13.13.47
106      j = 5
107      k = 5
108      call c_i(INT(5),5,'INT(integer)')
109      call c_i(INT(j),5,'INT(integer*2)')
110      call c_i(INT(k),5,'INT(integer*1)')
111      call c_i(INT(5.01),5,'INT(real)')
112      call c_i(INT(5.01d0),5,'INT(double)')
113c     Note: Does not accept optional second argument KIND
114
115c     MAX - Section 13.13.63
116      j = 1
117      j2 = 2
118      ja = 2
119      k = 1
120      k2 = 2
121      ka = 2
122      call c_i(MAX(1,2,3),3,'MAX(integer,integer,integer)')
123      call c_i2(MAX(j,j2),ja,'MAX(integer*2,integer*2)')
124      call c_i1(MAX(k,k2),ka,'MAX(integer*1,integer*1)')
125      call c_r(MAX(1.,2.,3.),3.,'MAX(real,real,real)')
126      call c_d(MAX(1.d0,2.d0,3.d0),3.d0,'MAX(double,double,double)')
127
128c     MIN - Section 13.13.68
129      j = 1
130      j2 = 2
131      ja = 1
132      k = 1
133      k2 = 2
134      ka = 1
135      call c_i(MIN(1,2,3),1,'MIN(integer,integer,integer)')
136      call c_i2(MIN(j,j2),ja,'MIN(integer*2,integer*2)')
137      call c_i1(MIN(k,k2),ka,'MIN(integer*1,integer*1)')
138      call c_r(MIN(1.,2.,3.),1.,'MIN(real,real,real)')
139      call c_d(MIN(1.d0,2.d0,3.d0),1.d0,'MIN(double,double,double)')
140
141c     MOD - Section 13.13.72
142      call c_i(MOD(8,5),3,'MOD(integer,integer) 1')
143      call c_i(MOD(-8,5),-3,'MOD(integer,integer) 2')
144      call c_i(MOD(8,-5),3,'MOD(integer,integer) 3')
145      call c_i(MOD(-8,-5),-3,'MOD(integer,integer) 4')
146      j = 8
147      j2 = 5
148      ja = 3
149      call c_i2(MOD(j,j2),ja,'MOD(integer*2,integer*2) 1')
150      call c_i2(MOD(-j,j2),-ja,'MOD(integer*2,integer*2) 2')
151      call c_i2(MOD(j,-j2),ja,'MOD(integer*2,integer*2) 3')
152      call c_i2(MOD(-j,-j2),-ja,'MOD(integer*2,integer*2) 4')
153      k = 8
154      k2 = 5
155      ka = 3
156      call c_i1(MOD(k,k2),ka,'MOD(integer*1,integer*1) 1')
157      call c_i1(MOD(-k,k2),-ka,'MOD(integer*1,integer*1) 2')
158      call c_i1(MOD(k,-k2),ka,'MOD(integer*1,integer*1) 3')
159      call c_i1(MOD(-k,-k2),-ka,'MOD(integer*1,integer*1) 4')
160      call c_r(MOD(8.,5.),3.,'MOD(real,real) 1')
161      call c_r(MOD(-8.,5.),-3.,'MOD(real,real) 2')
162      call c_r(MOD(8.,-5.),3.,'MOD(real,real) 3')
163      call c_r(MOD(-8.,-5.),-3.,'MOD(real,real) 4')
164      call c_d(MOD(8.d0,5.d0),3.d0,'MOD(double,double) 1')
165      call c_d(MOD(-8.d0,5.d0),-3.d0,'MOD(double,double) 2')
166      call c_d(MOD(8.d0,-5.d0),3.d0,'MOD(double,double) 3')
167      call c_d(MOD(-8.d0,-5.d0),-3.d0,'MOD(double,double) 4')
168
169c     MODULO - Section 13.13.73
170c     Not implemented
171
172c     NINT - Section 13.13.76
173      call c_i(NINT(2.783),3,'NINT(real)')
174      call c_i(NINT(2.783d0),3,'NINT(double)')
175c     Optional second argument KIND not implemented
176
177c     REAL - Section 13.13.86
178      j = -2
179      k = -2
180      call c_r(REAL(-2),-2.0,'REAL(integer)')
181      call c_r(REAL(j),-2.0,'REAL(integer*2)')
182      call c_r(REAL(k),-2.0,'REAL(integer*1)')
183      call c_r(REAL(-2.0),-2.0,'REAL(real)')
184      call c_r(REAL(-2.0d0),-2.0,'REAL(double)')
185      call c_r(REAL((-2.,9.)),-2.0,'REAL(complex)')
186c     REAL(double complex) not implemented
187c     call c_r(REAL((-2.d0,9.d0)),-2.0,'REAL(double complex)')
188
189c     SIGN - Section 13.13.96
190      j = -3
191      j2 = 2
192      ja = 3
193      k = -3
194      k2 = 2
195      ka = 3
196      call c_i(SIGN(-3,2),3,'SIGN(integer)')
197      call c_i2(SIGN(j,j2),ja,'SIGN(integer*2)')
198      call c_i1(SIGN(k,k2),ka,'SIGN(integer*1)')
199      call c_r(SIGN(-3.0,2.),3.,'SIGN(real,real)')
200      call c_d(SIGN(-3.d0,2.d0),3.d0,'SIGN(double,double)')
201
202      if ( fail ) call abort()
203      end
204
205      subroutine failure(label)
206c     Report failure and set flag
207      character*(*) label
208      logical fail
209      common /flags/ fail
210      write(6,'(a,a,a)') 'Test ',label,' FAILED'
211      fail = .true.
212      end
213
214      subroutine c_i(i,j,label)
215c     Check if INTEGER i equals j, and fail otherwise
216      integer i,j
217      character*(*) label
218      if ( i .ne. j ) then
219         call failure(label)
220         write(6,*) 'Got ',i,' expected ', j
221      end if
222      end
223
224      subroutine c_i2(i,j,label)
225c     Check if INTEGER*2 i equals j, and fail otherwise
226      integer*2 i,j
227      character*(*) label
228      if ( i .ne. j ) then
229         call failure(label)
230         write(6,*) 'Got ',i,' expected ', j
231      end if
232      end
233
234      subroutine c_i1(i,j,label)
235c     Check if INTEGER*1 i equals j, and fail otherwise
236      integer*1 i,j
237      character*(*) label
238      if ( i .ne. j ) then
239         call failure(label)
240         write(6,*) 'Got ',i,' expected ', j
241      end if
242      end
243
244      subroutine c_r(a,b,label)
245c     Check if REAL a equals b, and fail otherwise
246      real a, b
247      character*(*) label
248      if ( abs(a-b) .gt. 1.0e-5 ) then
249         call failure(label)
250         write(6,*) 'Got ',a,' expected ', b
251      end if
252      end
253
254      subroutine c_d(a,b,label)
255c     Check if DOUBLE PRECISION a equals b, and fail otherwise
256      double precision a, b
257      character*(*) label
258      if ( abs(a-b) .gt. 1.0d-5 ) then
259         call failure(label)
260         write(6,*) 'Got ',a,' expected ', b
261      end if
262      end
263
264      subroutine c_c(a,b,label)
265c     Check if COMPLEX a equals b, and fail otherwise
266      complex a, b
267      character*(*) label
268      if ( abs(a-b) .gt. 1.0e-5 ) then
269         call failure(label)
270         write(6,*) 'Got ',a,' expected ', b
271      end if
272      end
273
274      subroutine c_z(a,b,label)
275c     Check if COMPLEX a equals b, and fail otherwise
276      double complex a, b
277      character*(*) label
278      if ( abs(a-b) .gt. 1.0d-5 ) then
279         call failure(label)
280         write(6,*) 'Got ',a,' expected ', b
281      end if
282      end
283