Skip to content

Commit d3c0711

Browse files
committed
updated tests and readme for cpolyroots
1 parent 146177e commit d3c0711

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Method name | Polynomial type | Coefficients | Roots | Reference
3131
[`cmplx_roots_gen`](https://jacobwilliams.github.io/polyroots-fortran/proc/cmplx_roots_gen.html) | General | complex | complex | [Skowron & Gould (2012)](http://www.astrouw.edu.pl/~jskowron/cmplx_roots_sg/)
3232
[`fmpl`](https://jacobwilliams.github.io/polyroots-fortran/proc/fmpl.html) | General | complex | complex | [Cameron (2019)](https://link.springer.com/article/10.1007/s11075-018-0641-9)
3333
[`polyroots`](https://jacobwilliams.github.io/polyroots-fortran/proc/polyroots.html) | General | real | complex | --
34+
[`cpolyroots`](https://jacobwilliams.github.io/polyroots-fortran/proc/cpolyroots.html) | General | complex | complex | --
3435

3536
## Compiling
3637

test/polyroots_test.f90

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,39 @@ program polyroots_test
104104
write(*,'(A,1X/,*(g23.15/))') ' Coefficients: ', p(1:degree+1)
105105

106106
q = reverse(p) ! the following two accept the coefficients in reverse order
107+
do i = 1, degree+1
108+
cp(i) = cmplx(p(i), 0.0_wp, wp) ! put in a complex number
109+
end do
107110

108111
if (degree==2) then
109112
! also test this one (only for quadratic equations):
110-
write(*, '(A,1x,i3)') 'dqdcrt'
113+
write(*, '(/A,1x,i3)') 'dqdcrt'
111114
write(*, '(a)') ' real part imaginary part root'
112115
call dqdcrt(q, zr, zi)
113116
call check_results(0, zr, zi, degree)
114117
end if
115118

116119
if (degree==3) then
117120
! also test this one (only for cubic equations):
118-
write(*, '(A,1x,i3)') 'dcbcrt'
121+
write(*, '(/A,1x,i3)') 'dcbcrt'
119122
write(*, '(a)') ' real part imaginary part root'
120123
call dcbcrt(q, zr, zi)
121124
call check_results(0, zr, zi, degree)
122125
end if
123126

124-
write(*, '(A,1x,i3)') 'rpoly'
127+
if (wp /= REAL128) then
128+
write(*, '(/A,1x,i3)') 'polyroots'
129+
write(*, '(a)') ' real part imaginary part root'
130+
call polyroots(degree, p, zr, zi, istatus)
131+
call check_results(istatus, zr, zi, degree)
132+
133+
write(*, '(/A,1x,i3)') 'cpolyroots'
134+
write(*, '(a)') ' real part imaginary part root'
135+
call cpolyroots(degree, cp, r, istatus)
136+
call check_results(istatus, real(r, wp), aimag(r), degree)
137+
end if
138+
139+
write(*, '(/A,1x,i3)') 'rpoly'
125140
write(*, '(a)') ' real part imaginary part root'
126141
call rpoly(p, degree, zr, zi, istatus)
127142
call check_results(istatus, zr, zi, degree)
@@ -149,9 +164,6 @@ program polyroots_test
149164

150165
write(*, '(/A,1x,i3)') 'cpqr79'
151166
write(*, '(a)') ' real part imaginary part root'
152-
do i = 1, degree+1
153-
cp(i) = cmplx(p(i), 0.0_wp, wp) ! put in a complex number
154-
end do
155167
call cpqr79(degree,cp,r,istatus)
156168
call check_results(istatus, real(r,wp), aimag(r), degree)
157169

@@ -165,7 +177,9 @@ program polyroots_test
165177
write(*, '(a)') ' real part imaginary part root'
166178
cp = reversez(cp)
167179
call cmplx_roots_gen(degree, cp, r) ! no status flag
168-
call check_results(0, zr, zi, degree)
180+
rr = real(r, wp)
181+
rc = aimag(r)
182+
call check_results(0, rr, rc, degree)
169183

170184
write(*, '(/A,1x,i3)') 'polzeros'
171185
write(*, '(a)') ' real part imaginary part root'
@@ -181,13 +195,6 @@ program polyroots_test
181195
call fpml(cp, degree, r, berr, cond, conv, itmax=100)
182196
call check_results(0, real(r, wp), aimag(r), degree)
183197

184-
if (wp /= REAL128) then
185-
write(*, '(/A,1x,i3)') 'polyroots'
186-
write(*, '(a)') ' real part imaginary part root'
187-
call polyroots(degree, p, zr, zi, istatus)
188-
call check_results(istatus, zr, zi, degree)
189-
end if
190-
191198
end do
192199

193200
if (failure) error stop 'At least one test failed'

0 commit comments

Comments
 (0)