summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/complex_intrinsic_5.f90
blob: 49b8eaaa68e835329e292845cd5af3a94472e373 (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
! { dg-do run }
!
! PR fortran/33197
!
! Complex inverse trigonometric functions
! and complex inverse hyperbolic functions
!
! Run-time evaluation check
!
module test
  implicit none
  real(4), parameter :: eps4 = epsilon(0.0_4)*4.0_4
  real(8), parameter :: eps8 = epsilon(0.0_8)*2.0_8
  interface check
    procedure check4, check8
  end interface check
contains
  SUBROUTINE check4(z, zref)
    complex(4), intent(in) :: z, zref
    if (    abs (real(z)-real(zref)) > eps4 &
        .or.abs (aimag(z)-aimag(zref)) > eps4) then
      print '(a,/,2((2g0," + I ",g0),/))', "check4:","   z=",z,'zref=',zref
      print '(a,g0," + I*",g0,"  eps=",g0)', 'Diff: ', &
                                 real(z)-real(zref), &
                                 aimag(z)-aimag(zref), eps4
      call abort()
    end if
  END SUBROUTINE check4
  SUBROUTINE check8(z, zref)
    complex(8), intent(in) :: z, zref
    if (    abs (real(z)-real(zref)) > eps8 &
        .or.abs (aimag(z)-aimag(zref)) > eps8) then
      print '(a,/,2((2g0," + I ",g0),/))', "check8:","   z=",z,'zref=',zref
      print '(a,g0," + I*",g0,"  eps=",g0)', 'Diff: ', &
                                 real(z)-real(zref), &
                                 aimag(z)-aimag(zref), eps8
      call abort()
    end if
  END SUBROUTINE check8
end module test

PROGRAM ArcTrigHyp
  use test
  IMPLICIT NONE
  complex(4), volatile :: z4
  complex(8), volatile :: z8

!!!!! ZERO !!!!!!

  ! z = 0
  z4 = cmplx(0.0_4, 0.0_4, kind=4)
  z8 = cmplx(0.0_8, 0.0_8, kind=8)

  ! Exact: 0
  call check(asin(z4), cmplx(0.0_4, 0.0_4, kind=4))
  call check(asin(z8), cmplx(0.0_8, 0.0_8, kind=8))
  ! Exact: Pi/2 = 1.5707963267948966192313216916397514
  call check(acos(z4), cmplx(1.57079632679489661920_4, 0.0_4, kind=4))
  call check(acos(z8), cmplx(1.57079632679489661920_8, 0.0_8, kind=8))
  ! Exact: 0
  call check(atan(z4), cmplx(0.0_4, 0.0_4, kind=4))
  call check(atan(z8), cmplx(0.0_8, 0.0_8, kind=8))
  ! Exact: 0
  call check(asinh(z4), cmplx(0.0_4, 0.0_4, kind=4))
  call check(asinh(z8), cmplx(0.0_8, 0.0_8, kind=8))
  ! Exact: I*Pi/2 = I*1.5707963267948966192313216916397514
  call check(acosh(z4), cmplx(0.0_4, 1.57079632679489661920_4, kind=4))
  call check(acosh(z8), cmplx(0.0_8, 1.57079632679489661920_8, kind=8))
  ! Exact: 0
  call check(atanh(z4), cmplx(0.0_4, 0.0_4, kind=4))
  call check(atanh(z8), cmplx(0.0_8, 0.0_8, kind=8))


!!!!! POSITIVE NUMBERS !!!!!!

  ! z = tanh(1.0)
  z4 = cmplx(0.76159415595576488811945828260479359_4, 0.0_4, kind=4)
  z8 = cmplx(0.76159415595576488811945828260479359_8, 0.0_8, kind=8)

  ! Numerically: 0.86576948323965862428960184619184444
  call check(asin(z4), cmplx(0.86576948323965862428960184619184444_4, 0.0_4, kind=4))
  call check(asin(z8), cmplx(0.86576948323965862428960184619184444_8, 0.0_8, kind=8))
  ! Numerically: 0.70502684355523799494171984544790700
  call check(acos(z4), cmplx(0.70502684355523799494171984544790700_4, 0.0_4, kind=4))
  call check(acos(z8), cmplx(0.70502684355523799494171984544790700_8, 0.0_8, kind=8))
  ! Numerically: 0.65088016802300754993807813168285564
  call check(atan(z4), cmplx(0.65088016802300754993807813168285564_4, 0.0_4, kind=4))
  call check(atan(z8), cmplx(0.65088016802300754993807813168285564_8, 0.0_8, kind=8))
  ! Numerically: 0.70239670712987482778422106260749699
  call check(asinh(z4), cmplx(0.70239670712987482778422106260749699_4, 0.0_4, kind=4))
  call check(asinh(z8), cmplx(0.70239670712987482778422106260749699_8, 0.0_8, kind=8))
  ! Numerically: 0.70502684355523799494171984544790700*I
  call check(acosh(z4), cmplx(0.0_4, 0.70502684355523799494171984544790700_4, kind=4))
  call check(acosh(z8), cmplx(0.0_8, 0.70502684355523799494171984544790700_8, kind=8))
  ! Exact: 1
  call check(atanh(z4), cmplx(1.0_4, 0.0_4, kind=4))
  call check(atanh(z8), cmplx(1.0_8, 0.0_8, kind=8))


  ! z = I*tanh(1.0)
  z4 = cmplx(0.0_4, 0.76159415595576488811945828260479359_4, kind=4)
  z8 = cmplx(0.0_8, 0.76159415595576488811945828260479359_8, kind=8)

  ! Numerically: I*0.70239670712987482778422106260749699
  call check(asin(z4), cmplx(0.0_4, 0.70239670712987482778422106260749699_4, kind=4))
  call check(asin(z8), cmplx(0.0_8, 0.70239670712987482778422106260749699_8, kind=8))
  ! Numerically: 1.5707963267948966192313216916397514 - I*0.7023967071298748277842210626074970
  call check(acos(z4), cmplx(1.5707963267948966192313216916397514_4, -0.7023967071298748277842210626074970_4, kind=4))
  call check(acos(z8), cmplx(1.5707963267948966192313216916397514_8, -0.7023967071298748277842210626074970_8, kind=8))
  ! Exact: I*1
  call check(atan(z4), cmplx(0.0_4, 1.0_4, kind=4))
  call check(atan(z8), cmplx(0.0_8, 1.0_8, kind=8))
  ! Numerically: I*0.86576948323965862428960184619184444
  call check(asinh(z4), cmplx(0.0_4, 0.86576948323965862428960184619184444_4, kind=4))
  call check(asinh(z8), cmplx(0.0_8, 0.86576948323965862428960184619184444_8, kind=8))
  ! Numerically: 0.7023967071298748277842210626074970 + I*1.5707963267948966192313216916397514
  call check(acosh(z4), cmplx(0.7023967071298748277842210626074970_4, 1.5707963267948966192313216916397514_4, kind=4))
  call check(acosh(z8), cmplx(0.7023967071298748277842210626074970_8, 1.5707963267948966192313216916397514_8, kind=8))
  ! Numerically: I*0.65088016802300754993807813168285564
  call check(atanh(z4), cmplx(0.0_4, 0.65088016802300754993807813168285564_4, kind=4))
  call check(atanh(z8), cmplx(0.0_8, 0.65088016802300754993807813168285564_8, kind=8))


  ! z = (1+I)*tanh(1.0)
  z4 = cmplx(0.76159415595576488811945828260479359_4, 0.76159415595576488811945828260479359_4, kind=4)
  z8 = cmplx(0.76159415595576488811945828260479359_8, 0.76159415595576488811945828260479359_8, kind=8)

  ! Numerically: 0.59507386031622633330574869409179139 + I*0.82342412550090412964986631390412834
  call check(asin(z4), cmplx(0.59507386031622633330574869409179139_4, 0.82342412550090412964986631390412834_4, kind=4))
  call check(asin(z8), cmplx(0.59507386031622633330574869409179139_8, 0.82342412550090412964986631390412834_8, kind=8))
  ! Numerically: 0.97572246647867028592557299754796005 - I*0.82342412550090412964986631390412834
  call check(acos(z4), cmplx(0.97572246647867028592557299754796005_4, -0.82342412550090412964986631390412834_4, kind=4))
  call check(acos(z8), cmplx(0.97572246647867028592557299754796005_8, -0.82342412550090412964986631390412834_8, kind=8))
  ! Numerically: 0.83774433133636226305479129936568267 + I*0.43874835208710654149508159123595167
  call check(atan(z4), cmplx(0.83774433133636226305479129936568267_4, 0.43874835208710654149508159123595167_4, kind=4))
  call check(atan(z8), cmplx(0.83774433133636226305479129936568267_8, 0.43874835208710654149508159123595167_8, kind=8))
  ! Numerically: 0.82342412550090412964986631390412834 + I*0.59507386031622633330574869409179139
  call check(asinh(z4), cmplx(0.82342412550090412964986631390412834_4, 0.59507386031622633330574869409179139_4, kind=4))
  call check(asinh(z8), cmplx(0.82342412550090412964986631390412834_8, 0.59507386031622633330574869409179139_8, kind=8))
  ! Numerically: 0.82342412550090412964986631390412834 + I*0.97572246647867028592557299754796005
  call check(acosh(z4), cmplx(0.82342412550090412964986631390412834_4, 0.97572246647867028592557299754796005_4, kind=4))
  call check(acosh(z8), cmplx(0.82342412550090412964986631390412834_8, 0.97572246647867028592557299754796005_8, kind=8))
  ! Numerically: 0.43874835208710654149508159123595167 + I*0.83774433133636226305479129936568267
  call check(atanh(z4), cmplx(0.43874835208710654149508159123595167_4, 0.83774433133636226305479129936568267_4, kind=4))
  call check(atanh(z8), cmplx(0.43874835208710654149508159123595167_8, 0.83774433133636226305479129936568267_8, kind=8))


  ! z = 1+I
  z4 = cmplx(1.0_4, 1.0_4, kind=4)
  z8 = cmplx(1.0_8, 1.0_8, kind=8)

  ! Numerically: 0.66623943249251525510400489597779272 + I*1.06127506190503565203301891621357349
  call check(asin(z4), cmplx(0.66623943249251525510400489597779272_4, 1.06127506190503565203301891621357349_4, kind=4))
  call check(asin(z8), cmplx(0.66623943249251525510400489597779272_8, 1.06127506190503565203301891621357349_8, kind=8))
  ! Numerically: 0.90455689430238136412731679566195872 - I*1.06127506190503565203301891621357349
  call check(acos(z4), cmplx(0.90455689430238136412731679566195872_4, -1.06127506190503565203301891621357349_4, kind=4))
  call check(acos(z8), cmplx(0.90455689430238136412731679566195872_8, -1.06127506190503565203301891621357349_8, kind=8))
  ! Numerically: 1.01722196789785136772278896155048292 + I*0.40235947810852509365018983330654691
  call check(atan(z4), cmplx(1.01722196789785136772278896155048292_4, 0.40235947810852509365018983330654691_4, kind=4))
  call check(atan(z8), cmplx(1.01722196789785136772278896155048292_8, 0.40235947810852509365018983330654691_8, kind=8))
  ! Numerically: 1.06127506190503565203301891621357349 + I*0.66623943249251525510400489597779272
  call check(asinh(z4), cmplx(1.06127506190503565203301891621357349_4, 0.66623943249251525510400489597779272_4, kind=4))
  call check(asinh(z8), cmplx(1.06127506190503565203301891621357349_8, 0.66623943249251525510400489597779272_8, kind=8))
  ! Numerically: 1.06127506190503565203301891621357349 + I*0.90455689430238136412731679566195872
  call check(acosh(z4), cmplx(1.06127506190503565203301891621357349_4, 0.90455689430238136412731679566195872_4, kind=4))
  call check(acosh(z8), cmplx(1.06127506190503565203301891621357349_8, 0.90455689430238136412731679566195872_8, kind=8))
  ! Numerically: 0.40235947810852509365018983330654691 + I*1.01722196789785136772278896155048292
  call check(atanh(z4), cmplx(0.40235947810852509365018983330654691_4, 1.01722196789785136772278896155048292_4, kind=4))
  call check(atanh(z8), cmplx(0.40235947810852509365018983330654691_8, 1.01722196789785136772278896155048292_8, kind=8))


  ! z = (1+I)*1.1
  z4 = cmplx(1.1_4, 1.1_4, kind=4)
  z8 = cmplx(1.1_8, 1.1_8, kind=8)

  ! Numerically: 0.68549840630267734494444454677951503 + I*1.15012680127435581678415521738176733
  call check(asin(z4), cmplx(0.68549840630267734494444454677951503_4, 1.15012680127435581678415521738176733_4, kind=4))
  call check(asin(z8), cmplx(0.68549840630267734494444454677951503_8, 1.15012680127435581678415521738176733_8, kind=8))
  ! Numerically: 0.8852979204922192742868771448602364 - I*1.1501268012743558167841552173817673
  call check(acos(z4), cmplx(0.8852979204922192742868771448602364_4, -1.1501268012743558167841552173817673_4, kind=4))
  call check(acos(z8), cmplx(0.8852979204922192742868771448602364_8, -1.1501268012743558167841552173817673_8, kind=8))
  ! Numerically: 1.07198475450905931839240655913126728 + I*0.38187020129010862908881230531688930
  call check(atan(z4), cmplx(1.07198475450905931839240655913126728_4, 0.38187020129010862908881230531688930_4, kind=4))
  call check(atan(z8), cmplx(1.07198475450905931839240655913126728_8, 0.38187020129010862908881230531688930_8, kind=8))
  ! Numerically: 1.15012680127435581678415521738176733 + I*0.68549840630267734494444454677951503
  call check(asinh(z4), cmplx(1.15012680127435581678415521738176733_4, 0.68549840630267734494444454677951503_4, kind=4))
  call check(asinh(z8), cmplx(1.15012680127435581678415521738176733_8, 0.68549840630267734494444454677951503_8, kind=8))
  ! Numerically: 1.1501268012743558167841552173817673 + I*0.8852979204922192742868771448602364
  call check(acosh(z4), cmplx(1.1501268012743558167841552173817673_4, 0.8852979204922192742868771448602364_4, kind=4))
  call check(acosh(z8), cmplx(1.1501268012743558167841552173817673_8, 0.8852979204922192742868771448602364_8, kind=8))
  ! Numerically: 0.38187020129010862908881230531688930 + I*1.07198475450905931839240655913126728
  call check(atanh(z4), cmplx(0.38187020129010862908881230531688930_4, 1.07198475450905931839240655913126728_4, kind=4))
  call check(atanh(z8), cmplx(0.38187020129010862908881230531688930_8, 1.07198475450905931839240655913126728_8, kind=8))


!!!!! Negative NUMBERS !!!!!!
  ! z = -(1+I)*1.1
  z4 = cmplx(-1.1_4, -1.1_4, kind=4)
  z8 = cmplx(-1.1_8, -1.1_8, kind=8)

  ! Numerically: -0.68549840630267734494444454677951503 - I*1.15012680127435581678415521738176733
  call check(asin(z4), cmplx(-0.68549840630267734494444454677951503_4, -1.15012680127435581678415521738176733_4, kind=4))
  call check(asin(z8), cmplx(-0.68549840630267734494444454677951503_8, -1.15012680127435581678415521738176733_8, kind=8))
  ! Numerically: 2.2562947330975739641757662384192665 + I*1.1501268012743558167841552173817673
  call check(acos(z4), cmplx(2.2562947330975739641757662384192665_4, 1.1501268012743558167841552173817673_4, kind=4))
  call check(acos(z8), cmplx(2.2562947330975739641757662384192665_8, 1.1501268012743558167841552173817673_8, kind=8))
  ! Numerically: -1.07198475450905931839240655913126728 - I*0.38187020129010862908881230531688930
  call check(atan(z4), cmplx(-1.07198475450905931839240655913126728_4, -0.38187020129010862908881230531688930_4, kind=4))
  call check(atan(z8), cmplx(-1.07198475450905931839240655913126728_8, -0.38187020129010862908881230531688930_8, kind=8))
  ! Numerically: -1.15012680127435581678415521738176733 - I*0.68549840630267734494444454677951503
  call check(asinh(z4), cmplx(-1.15012680127435581678415521738176733_4, -0.68549840630267734494444454677951503_4, kind=4))
  call check(asinh(z8), cmplx(-1.15012680127435581678415521738176733_8, -0.68549840630267734494444454677951503_8, kind=8))
  ! Numerically: 1.1501268012743558167841552173817673 - I*2.2562947330975739641757662384192665
  call check(acosh(z4), cmplx(1.1501268012743558167841552173817673_4, -2.2562947330975739641757662384192665_4, kind=4))
  call check(acosh(z8), cmplx(1.1501268012743558167841552173817673_8, -2.2562947330975739641757662384192665_8, kind=8))
  ! Numerically: 0.38187020129010862908881230531688930 + I*1.07198475450905931839240655913126728
  call check(atanh(z4), cmplx(-0.38187020129010862908881230531688930_4, -1.07198475450905931839240655913126728_4, kind=4))
  call check(atanh(z8), cmplx(-0.38187020129010862908881230531688930_8, -1.07198475450905931839240655913126728_8, kind=8))
END PROGRAM ArcTrigHyp

! { dg-final { cleanup-modules "test" } }