| 1 |
! Program to test elemental functions. |
| 2 |
program test_elemental |
| 3 |
implicit none |
| 4 |
integer, dimension (2, 4) :: a |
| 5 |
integer, dimension (2, 4) :: b |
| 6 |
integer(kind = 8), dimension(2) :: c |
| 7 |
|
| 8 |
a = reshape ((/2, 3, 4, 5, 6, 7, 8, 9/), (/2, 4/)) |
| 9 |
b = 0 |
| 10 |
b(2, :) = e_fn (a(1, :), 1) |
| 11 |
if (any (b .ne. reshape ((/0, 1, 0, 3, 0, 5, 0, 7/), (/2, 4/)))) STOP 1 |
| 12 |
a = e_fn (a(:, 4:1:-1), 1 + b) |
| 13 |
if (any (a .ne. reshape ((/7, 7, 5, 3, 3, -1, 1, -5/), (/2, 4/)))) STOP 2 |
| 14 |
! This tests intrinsic elemental conversion functions. |
| 15 |
c = 2 * a(1, 1) |
| 16 |
if (any (c .ne. 14)) STOP 3 |
| 17 |
|
| 18 |
! This triggered bug due to building ss chains in the wrong order. |
| 19 |
b = 0; |
| 20 |
a = a - e_fn (a, b) |
| 21 |
if (any (a .ne. 0)) STOP 4 |
| 22 |
|
| 23 |
! Check expressions involving constants |
| 24 |
a = e_fn (b + 1, 1) |
| 25 |
if (any (a .ne. 0)) STOP 5 |
| 26 |
contains |
| 27 |
|
| 28 |
elemental integer(kind=4) function e_fn (p, q) |
| 29 |
integer, intent(in) :: p, q |
| 30 |
e_fn = p - q |
| 31 |
end function |
| 32 |
end program |