summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/integer_exponentiation_2.f90
blob: d55f70c9a95b8cfc3a16c74291f95b6805cd17cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
! { dg-do run }
! { dg-options "" }
! Test various exponentations
! initially designed for patch to PR31120

program test
  call run_me (1.0, 1, (1.0,0.0))
  call run_me (-1.1, -1, (0.0,-1.0))
  call run_me (42.0, 12, (1.0,7.0))
end program test

! This subroutine is for runtime tests
subroutine run_me(a, i, z)
  implicit none

  real, intent(in) :: a
  integer, intent(in) :: i
  complex, intent(in) :: z

  call check_equal_i (i**0, 1)
  call check_equal_i (i**1, i)
  call check_equal_i (i**2, i*i)
  call check_equal_i (i**3, i*(i**2))

  ! i has default integer kind.
  call check_equal_i (int(i**0_8,kind=kind(i)), 1)
  call check_equal_i (int(i**1_8,kind=kind(i)), i)
  call check_equal_i (int(i**2_8,kind=kind(i)), i*i)
  call check_equal_i (int(i**3_8,kind=kind(i)), i*i*i)

  call check_equal_r (a**0.0, 1.0)
  call check_equal_r (a**1.0, a)
  call check_equal_r (a**2.0, a*a)
  call check_equal_r (a**3.0, a*(a**2))
  call check_equal_r (a**(-1.0), 1/a)
  call check_equal_r (a**(-2.0), (1/a)*(1/a))

  call check_equal_r (a**0, 1.0)
  call check_equal_r (a**1, a)
  call check_equal_r (a**2, a*a)
  call check_equal_r (a**3, a*(a**2))
  call check_equal_r (a**(-1), 1/a)
  call check_equal_r (a**(-2), (1/a)*(1/a))

  call check_equal_r (a**0_8, 1.0)
  call check_equal_r (a**1_8, a)
  call check_equal_r (a**2_8, a*a)
  call check_equal_r (a**3_8, a*(a**2))
  call check_equal_r (a**(-1_8), 1/a)
  call check_equal_r (a**(-2_8), (1/a)*(1/a))

  call check_equal_c (z**0.0, (1.0,0.0))
  call check_equal_c (z**1.0, z)
  call check_equal_c (z**2.0, z*z)
  call check_equal_c (z**3.0, z*(z**2))
  call check_equal_c (z**(-1.0), 1/z)
  call check_equal_c (z**(-2.0), (1/z)*(1/z))

  call check_equal_c (z**(0.0,0.0), (1.0,0.0))
  call check_equal_c (z**(1.0,0.0), z)
  call check_equal_c (z**(2.0,0.0), z*z)
  call check_equal_c (z**(3.0,0.0), z*(z**2))
  call check_equal_c (z**(-1.0,0.0), 1/z)
  call check_equal_c (z**(-2.0,0.0), (1/z)*(1/z))

  call check_equal_c (z**0, (1.0,0.0))
  call check_equal_c (z**1, z)
  call check_equal_c (z**2, z*z)
  call check_equal_c (z**3, z*(z**2))
  call check_equal_c (z**(-1), 1/z)
  call check_equal_c (z**(-2), (1/z)*(1/z))

  call check_equal_c (z**0_8, (1.0,0.0))
  call check_equal_c (z**1_8, z)
  call check_equal_c (z**2_8, z*z)
  call check_equal_c (z**3_8, z*(z**2))
  call check_equal_c (z**(-1_8), 1/z)
  call check_equal_c (z**(-2_8), (1/z)*(1/z))


contains

  subroutine check_equal_r (a, b)
    real, intent(in) :: a, b
    if (abs(a - b) > 1.e-5 * abs(b)) call abort
  end subroutine check_equal_r

  subroutine check_equal_c (a, b)
    complex, intent(in) :: a, b
    if (abs(a - b) > 1.e-5 * abs(b)) call abort
  end subroutine check_equal_c

  subroutine check_equal_i (a, b)
    integer, intent(in) :: a, b
    if (a /= b) call abort
  end subroutine check_equal_i

end subroutine run_me

! subroutine foo is used for compilation test only
subroutine foo(a)
  implicit none

  real, intent(in) :: a
  integer :: i
  complex :: z

  ! Integer
  call gee_i(i**0_1)
  call gee_i(i**1_1)
  call gee_i(i**2_1)
  call gee_i(i**3_1)
  call gee_i(i**(-1_1))
  call gee_i(i**(-2_1))
  call gee_i(i**(-3_1))
  call gee_i(i**huge(0_1))
  call gee_i(i**(-huge(0_1)))
  call gee_i(i**(-huge(0_1)-1_1))

  call gee_i(i**0_2)
  call gee_i(i**1_2)
  call gee_i(i**2_2)
  call gee_i(i**3_2)
  call gee_i(i**(-1_2))
  call gee_i(i**(-2_2))
  call gee_i(i**(-3_2))
  call gee_i(i**huge(0_2))
  call gee_i(i**(-huge(0_2)))
  call gee_i(i**(-huge(0_2)-1_2))

  call gee_i(i**0_4)
  call gee_i(i**1_4)
  call gee_i(i**2_4)
  call gee_i(i**3_4)
  call gee_i(i**(-1_4))
  call gee_i(i**(-2_4))
  call gee_i(i**(-3_4))
  call gee_i(i**huge(0_4))
  call gee_i(i**(-huge(0_4)))
  call gee_i(i**(-huge(0_4)-1_4))

  call gee_i(i**0_8) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**1_8) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**2_8) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**3_8) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**(-1_8)) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**(-2_8)) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**(-3_8)) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**huge(0_8)) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**(-huge(0_8))) ! { dg-warning "Type mismatch in argument" }
  call gee_i(i**(-huge(0_8)-1_8)) ! { dg-warning "Type mismatch in argument" }

  ! Real
  call gee_r(a**0_1)
  call gee_r(a**1_1)
  call gee_r(a**2_1)
  call gee_r(a**3_1)
  call gee_r(a**(-1_1))
  call gee_r(a**(-2_1))
  call gee_r(a**(-3_1))
  call gee_r(a**huge(0_1))
  call gee_r(a**(-huge(0_1)))
  call gee_r(a**(-huge(0_1)-1_1))

  call gee_r(a**0_2)
  call gee_r(a**1_2)
  call gee_r(a**2_2)
  call gee_r(a**3_2)
  call gee_r(a**(-1_2))
  call gee_r(a**(-2_2))
  call gee_r(a**(-3_2))
  call gee_r(a**huge(0_2))
  call gee_r(a**(-huge(0_2)))
  call gee_r(a**(-huge(0_2)-1_2))

  call gee_r(a**0_4)
  call gee_r(a**1_4)
  call gee_r(a**2_4)
  call gee_r(a**3_4)
  call gee_r(a**(-1_4))
  call gee_r(a**(-2_4))
  call gee_r(a**(-3_4))
  call gee_r(a**huge(0_4))
  call gee_r(a**(-huge(0_4)))
  call gee_r(a**(-huge(0_4)-1_4))

  call gee_r(a**0_8)
  call gee_r(a**1_8)
  call gee_r(a**2_8)
  call gee_r(a**3_8)
  call gee_r(a**(-1_8))
  call gee_r(a**(-2_8))
  call gee_r(a**(-3_8))
  call gee_r(a**huge(0_8))
  call gee_r(a**(-huge(0_8)))
  call gee_r(a**(-huge(0_8)-1_8))

  ! Complex
  call gee_z(z**0_1)
  call gee_z(z**1_1)
  call gee_z(z**2_1)
  call gee_z(z**3_1)
  call gee_z(z**(-1_1))
  call gee_z(z**(-2_1))
  call gee_z(z**(-3_1))
  call gee_z(z**huge(0_1))
  call gee_z(z**(-huge(0_1)))
  call gee_z(z**(-huge(0_1)-1_1))

  call gee_z(z**0_2)
  call gee_z(z**1_2)
  call gee_z(z**2_2)
  call gee_z(z**3_2)
  call gee_z(z**(-1_2))
  call gee_z(z**(-2_2))
  call gee_z(z**(-3_2))
  call gee_z(z**huge(0_2))
  call gee_z(z**(-huge(0_2)))
  call gee_z(z**(-huge(0_2)-1_2))

  call gee_z(z**0_4)
  call gee_z(z**1_4)
  call gee_z(z**2_4)
  call gee_z(z**3_4)
  call gee_z(z**(-1_4))
  call gee_z(z**(-2_4))
  call gee_z(z**(-3_4))
  call gee_z(z**huge(0_4))
  call gee_z(z**(-huge(0_4)))
  call gee_z(z**(-huge(0_4)-1_4))

  call gee_z(z**0_8)
  call gee_z(z**1_8)
  call gee_z(z**2_8)
  call gee_z(z**3_8)
  call gee_z(z**(-1_8))
  call gee_z(z**(-2_8))
  call gee_z(z**(-3_8))
  call gee_z(z**huge(0_8))
  call gee_z(z**(-huge(0_8)))
  call gee_z(z**(-huge(0_8)-1_8))
end subroutine foo

subroutine gee_i(i)
  integer :: i
end subroutine gee_i

subroutine gee_r(r)
  real :: r
end subroutine gee_r

subroutine gee_z(c)
  complex :: c
end subroutine gee_z