| 1 |
694 |
jeremybenn |
c { dg-do run }
|
| 2 |
|
|
c f90-intrinsic-numeric.f
|
| 3 |
|
|
c
|
| 4 |
|
|
c Test Fortran 90 intrinsic numeric functions - Section 13.10.2 and 13.13
|
| 5 |
|
|
c David Billinghurst <David.Billinghurst@riotinto.com>
|
| 6 |
|
|
c
|
| 7 |
|
|
c Notes:
|
| 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
|
| 10 |
|
|
c intrinsic77.f
|
| 11 |
|
|
|
| 12 |
|
|
logical fail
|
| 13 |
|
|
integer(kind=2) j, j2, ja
|
| 14 |
|
|
integer(kind=1) k, k2, ka
|
| 15 |
|
|
|
| 16 |
|
|
common /flags/ fail
|
| 17 |
|
|
fail = .false.
|
| 18 |
|
|
|
| 19 |
|
|
c ABS - Section 13.13.1
|
| 20 |
|
|
j = -9
|
| 21 |
|
|
ja = 9
|
| 22 |
|
|
k = j
|
| 23 |
|
|
ka = ja
|
| 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))')
|
| 31 |
|
|
|
| 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))')
|
| 36 |
|
|
|
| 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
|
| 43 |
|
|
|
| 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
|
| 50 |
|
|
|
| 51 |
|
|
c CEILING - Section 13.13.18
|
| 52 |
|
|
c Not implemented
|
| 53 |
|
|
|
| 54 |
|
|
c CMPLX - Section 13.13.20
|
| 55 |
|
|
j = 1
|
| 56 |
|
|
ja = 2
|
| 57 |
|
|
k = 1
|
| 58 |
|
|
ka = 2
|
| 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
|
| 71 |
|
|
|
| 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))')
|
| 75 |
|
|
|
| 76 |
|
|
c DBLE - Section 13.13.27
|
| 77 |
|
|
j = 5
|
| 78 |
|
|
k = 5
|
| 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))')
|
| 86 |
|
|
|
| 87 |
|
|
c DIM - Section 13.13.29
|
| 88 |
|
|
j = -8
|
| 89 |
|
|
j2 = -3
|
| 90 |
|
|
ja = 0
|
| 91 |
|
|
k = -8
|
| 92 |
|
|
k2 = -3
|
| 93 |
|
|
ka = 0
|
| 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)')
|
| 99 |
|
|
|
| 100 |
|
|
c DPROD - Section 13.13.31
|
| 101 |
|
|
call c_d(DPROD(-8.,-3.),24.d0,'DPROD(real,real)')
|
| 102 |
|
|
|
| 103 |
|
|
c FLOOR - Section 13.13.36
|
| 104 |
|
|
c Not implemented
|
| 105 |
|
|
|
| 106 |
|
|
c INT - Section 13.13.47
|
| 107 |
|
|
j = 5
|
| 108 |
|
|
k = 5
|
| 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
|
| 115 |
|
|
|
| 116 |
|
|
c MAX - Section 13.13.63
|
| 117 |
|
|
j = 1
|
| 118 |
|
|
j2 = 2
|
| 119 |
|
|
ja = 2
|
| 120 |
|
|
k = 1
|
| 121 |
|
|
k2 = 2
|
| 122 |
|
|
ka = 2
|
| 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)')
|
| 128 |
|
|
|
| 129 |
|
|
c MIN - Section 13.13.68
|
| 130 |
|
|
j = 1
|
| 131 |
|
|
j2 = 2
|
| 132 |
|
|
ja = 1
|
| 133 |
|
|
k = 1
|
| 134 |
|
|
k2 = 2
|
| 135 |
|
|
ka = 1
|
| 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)')
|
| 141 |
|
|
|
| 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')
|
| 147 |
|
|
j = 8
|
| 148 |
|
|
j2 = 5
|
| 149 |
|
|
ja = 3
|
| 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')
|
| 154 |
|
|
k = 8
|
| 155 |
|
|
k2 = 5
|
| 156 |
|
|
ka = 3
|
| 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')
|
| 169 |
|
|
|
| 170 |
|
|
c MODULO - Section 13.13.73
|
| 171 |
|
|
c Not implemented
|
| 172 |
|
|
|
| 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
|
| 177 |
|
|
|
| 178 |
|
|
c REAL - Section 13.13.86
|
| 179 |
|
|
j = -2
|
| 180 |
|
|
k = -2
|
| 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))')
|
| 189 |
|
|
|
| 190 |
|
|
c SIGN - Section 13.13.96
|
| 191 |
|
|
j = -3
|
| 192 |
|
|
j2 = 2
|
| 193 |
|
|
ja = 3
|
| 194 |
|
|
k = -3
|
| 195 |
|
|
k2 = 2
|
| 196 |
|
|
ka = 3
|
| 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)')
|
| 202 |
|
|
|
| 203 |
|
|
if ( fail ) call abort()
|
| 204 |
|
|
end
|
| 205 |
|
|
|
| 206 |
|
|
subroutine failure(label)
|
| 207 |
|
|
c Report failure and set flag
|
| 208 |
|
|
character*(*) label
|
| 209 |
|
|
logical fail
|
| 210 |
|
|
common /flags/ fail
|
| 211 |
|
|
write(6,'(a,a,a)') 'Test ',label,' FAILED'
|
| 212 |
|
|
fail = .true.
|
| 213 |
|
|
end
|
| 214 |
|
|
|
| 215 |
|
|
subroutine c_i(i,j,label)
|
| 216 |
|
|
c Check if INTEGER i equals j, and fail otherwise
|
| 217 |
|
|
integer i,j
|
| 218 |
|
|
character*(*) label
|
| 219 |
|
|
if ( i .ne. j ) then
|
| 220 |
|
|
call failure(label)
|
| 221 |
|
|
write(6,*) 'Got ',i,' expected ', j
|
| 222 |
|
|
end if
|
| 223 |
|
|
end
|
| 224 |
|
|
|
| 225 |
|
|
subroutine c_i2(i,j,label)
|
| 226 |
|
|
c Check if INTEGER(kind=2) i equals j, and fail otherwise
|
| 227 |
|
|
integer(kind=2) i,j
|
| 228 |
|
|
character*(*) label
|
| 229 |
|
|
if ( i .ne. j ) then
|
| 230 |
|
|
call failure(label)
|
| 231 |
|
|
write(6,*) 'Got ',i,' expected ', j
|
| 232 |
|
|
end if
|
| 233 |
|
|
end
|
| 234 |
|
|
|
| 235 |
|
|
subroutine c_i1(i,j,label)
|
| 236 |
|
|
c Check if INTEGER(kind=1) i equals j, and fail otherwise
|
| 237 |
|
|
integer(kind=1) i,j
|
| 238 |
|
|
character*(*) label
|
| 239 |
|
|
if ( i .ne. j ) then
|
| 240 |
|
|
call failure(label)
|
| 241 |
|
|
write(6,*) 'Got ',i,' expected ', j
|
| 242 |
|
|
end if
|
| 243 |
|
|
end
|
| 244 |
|
|
|
| 245 |
|
|
subroutine c_r(a,b,label)
|
| 246 |
|
|
c Check if REAL a equals b, and fail otherwise
|
| 247 |
|
|
real a, b
|
| 248 |
|
|
character*(*) label
|
| 249 |
|
|
if ( abs(a-b) .gt. 1.0e-5 ) then
|
| 250 |
|
|
call failure(label)
|
| 251 |
|
|
write(6,*) 'Got ',a,' expected ', b
|
| 252 |
|
|
end if
|
| 253 |
|
|
end
|
| 254 |
|
|
|
| 255 |
|
|
subroutine c_d(a,b,label)
|
| 256 |
|
|
c Check if DOUBLE PRECISION a equals b, and fail otherwise
|
| 257 |
|
|
double precision a, b
|
| 258 |
|
|
character*(*) label
|
| 259 |
|
|
if ( abs(a-b) .gt. 1.0d-5 ) then
|
| 260 |
|
|
call failure(label)
|
| 261 |
|
|
write(6,*) 'Got ',a,' expected ', b
|
| 262 |
|
|
end if
|
| 263 |
|
|
end
|
| 264 |
|
|
|
| 265 |
|
|
subroutine c_c(a,b,label)
|
| 266 |
|
|
c Check if COMPLEX a equals b, and fail otherwise
|
| 267 |
|
|
complex a, b
|
| 268 |
|
|
character*(*) label
|
| 269 |
|
|
if ( abs(a-b) .gt. 1.0e-5 ) then
|
| 270 |
|
|
call failure(label)
|
| 271 |
|
|
write(6,*) 'Got ',a,' expected ', b
|
| 272 |
|
|
end if
|
| 273 |
|
|
end
|
| 274 |
|
|
|
| 275 |
|
|
subroutine c_z(a,b,label)
|
| 276 |
|
|
c Check if COMPLEX a equals b, and fail otherwise
|
| 277 |
|
|
complex(kind=8) a, b
|
| 278 |
|
|
character*(*) label
|
| 279 |
|
|
if ( abs(a-b) .gt. 1.0d-5 ) then
|
| 280 |
|
|
call failure(label)
|
| 281 |
|
|
write(6,*) 'Got ',a,' expected ', b
|
| 282 |
|
|
end if
|
| 283 |
|
|
end
|