Skip to content

Commit b86491d

Browse files
committed
Add support for different real kinds
1 parent 8f1f4e4 commit b86491d

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

src/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SRCF90 = \
6060
fftpack_qct.f90\
6161
fftpack_iqct.f90\
6262
fftpack_dct.f90\
63-
rk.f90
63+
rk.F90
6464

6565
OBJF := $(SRCF:.f90=.o)
6666
OBJF90 := $(SRCF90:.f90=.o)
@@ -74,6 +74,9 @@ shared: $(OBJ)
7474
clean:
7575
rm -f -r *.o *.a *.so *.mod *.smod
7676

77+
%.o: %.F90
78+
$(FC) $(FFLAGS) -c $<
79+
7780
%.o: %.f90
7881
$(FC) $(FFLAGS) -c $<
7982

src/rk.F90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
!> fftpack kind
2+
module fftpack_kind
3+
implicit none
4+
5+
!> fftpack real kind
6+
#if defined(fftpack_sp)
7+
integer, parameter :: rk = selected_real_kind(6)
8+
#elif defined(fftpack_xdp)
9+
integer, parameter :: rk = selected_real_kind(18)
10+
#elif defined(fftpack_qp)
11+
integer, parameter :: rk = selected_real_kind(33)
12+
#else
13+
integer, parameter :: rk = selected_real_kind(15)
14+
#endif
15+
16+
end module fftpack_kind

src/rk.f90

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ testdrive.F90:
2929
$(FETCH) https://github.com/fortran-lang/test-drive/raw/v0.4.0/src/testdrive.F90 > $@
3030

3131
%.o: %.F90
32-
$(FC) $(FFLAGS) -c $<
32+
$(FC) $(FFLAGS) -I../src -c $<
3333

3434
%.o: %.f90
3535
$(FC) $(FFLAGS) -I../src -c $<

test/test_fftpack_dct.f90 renamed to test/test_fftpack_dct.F90

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module test_fftpack_dct
77

88
public :: collect_dct
99

10+
#if defined(fftpack_sp)
11+
real(kind=rk) :: eps = 1.0e-5_rk
12+
#else
13+
real(kind=rk) :: eps = 1.0e-10_rk
14+
#endif
15+
1016
contains
1117

1218
!> Collect all exported unit tests
@@ -26,15 +32,16 @@ subroutine test_classic_dct(error)
2632
type(error_type), allocatable, intent(out) :: error
2733
real(kind=rk) :: w(3*4 + 15)
2834
real(kind=rk) :: x(4) = [1, 2, 3, 4]
29-
real(kind=rk) :: eps = 1.0e-10_rk
3035

3136
call dcosti(4, w)
3237
call dcost(4, x, w)
33-
call check(error, all(x == [real(kind=rk) :: 15, -4, 0, -1.0000000000000009_rk]), "`dcosti` failed.")
38+
call check(error, sum(abs(x - [real(kind=rk) :: 15, -4, 0, -1.0000000000000009_rk])) < eps, &
39+
"`dcosti` failed.")
3440
if (allocated(error)) return
3541

3642
call dcost(4, x, w)
37-
call check(error, all(x/(2.0_rk*(4.0_rk - 1.0_rk)) == [real(kind=rk) :: 1, 2, 3, 4]), "`dcost` failed.")
43+
call check(error, sum(abs(x/(2.0_rk*(4.0_rk - 1.0_rk)) - &
44+
[real(kind=rk) :: 1, 2, 3, 4])) < eps, "`dcost` failed.")
3845

3946
end subroutine test_classic_dct
4047

@@ -46,23 +53,25 @@ subroutine test_modernized_dct(error)
4653
if (allocated(error)) return
4754
call check(error, all(dct(x, 3) == dct(x)), "`dct(x, 3)` failed.")
4855
if (allocated(error)) return
49-
call check(error, all(dct(x, 4) == [real(kind=rk) :: -3, -3.0000000000000036_rk, 15, 33]), "`dct(x, 4)` failed.")
56+
call check(error, sum(abs(dct(x, 4) - [real(kind=rk) :: -3, -3.0000000000000036_rk, 15, 33])) &
57+
< eps, "`dct(x, 4)` failed.")
5058

5159
end subroutine test_modernized_dct
5260

5361
subroutine test_modernized_idct(error)
5462
type(error_type), allocatable, intent(out) :: error
55-
real(kind=rk) :: eps = 1.0e-10_rk
5663
real(kind=rk) :: x(4) = [1, 2, 3, 4]
5764

58-
call check(error, all(idct(dct(x))/(2.0_rk*(4.0_rk - 1.0_rk)) == [real(kind=rk) :: 1, 2, 3, 4]), &
65+
call check(error, sum(abs(idct(dct(x))/(2.0_rk*(4.0_rk - 1.0_rk)) - &
66+
[real(kind=rk) :: 1, 2, 3, 4])) < eps, &
5967
"`idct(dct(x))/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
6068
if (allocated(error)) return
6169
call check(error, all(idct(dct(x), 2)/(2.0_rk*(2.0_rk - 1.0_rk)) == [real(kind=rk) :: 5.5, 9.5]), &
6270
"`idct(dct(x), 2)/(2.0_rk*(2.0_rk-1.0_rk))` failed.")
6371
if (allocated(error)) return
64-
call check(error, all(idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk - 1.0_rk)) == &
65-
[0.16666666666666666_rk, 0.33333333333333331_rk, 0.66666666666666663_rk, 0.83333333333333315_rk]), &
72+
call check(error, sum(abs(idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk - 1.0_rk)) - &
73+
[0.16666666666666666_rk, 0.33333333333333331_rk, &
74+
0.66666666666666663_rk, 0.83333333333333315_rk])) < eps, &
6675
"`idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
6776

6877
end subroutine test_modernized_idct

test/test_fftpack_qct.f90 renamed to test/test_fftpack_qct.F90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module test_fftpack_qct
77

88
public :: collect_qct
99

10+
#if defined(fftpack_sp)
11+
real(kind=rk) :: eps = 1.0e-5_rk
12+
#else
13+
real(kind=rk) :: eps = 1.0e-10_rk
14+
#endif
15+
1016
contains
1117

1218
!> Collect all exported unit tests
@@ -26,7 +32,6 @@ subroutine test_classic_qct(error)
2632
type(error_type), allocatable, intent(out) :: error
2733
real(kind=rk) :: w(3*4 + 15)
2834
real(kind=rk) :: x(4) = [1, 2, 3, 4]
29-
real(kind=rk) :: eps = 1.0e-10_rk
3035

3136
call dcosqi(4, w)
3237
call dcosqf(4, x, w)
@@ -42,7 +47,6 @@ end subroutine test_classic_qct
4247

4348
subroutine test_modernized_qct(error)
4449
type(error_type), allocatable, intent(out) :: error
45-
real(kind=rk) :: eps = 1.0e-10_rk
4650
real(kind=rk) :: x(3) = [9, -9, 3]
4751

4852
call check(error, sum(abs(qct(x, 2) - [-3.7279220613578570_rk, 21.727922061357859_rk])) < eps, &
@@ -59,7 +63,6 @@ end subroutine test_modernized_qct
5963

6064
subroutine test_modernized_iqct(error)
6165
type(error_type), allocatable, intent(out) :: error
62-
real(kind=rk) :: eps = 1.0e-10_rk
6366
real(kind=rk) :: x(4) = [1, 2, 3, 4]
6467

6568
call check(error, sum(abs(iqct(qct(x))/(4.0_rk*4.0_rk) - [real(kind=rk) :: 1, 2, 3, 4])) < eps, &

0 commit comments

Comments
 (0)