Skip to content

Commit b718f78

Browse files
committed
Make support for quadruple precision optional
- use checks in CMake to automatically determine whether quadruple precision is available - default to values in kind we run from the manual makefile don't want to run checks - skip all tests explicitly referencing the quadruple precision kind parameter - add check for extended double precision (available with GCC)
1 parent f58da3b commit b718f78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+332
-113
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
2424
add_compile_options(-Wall)
2525
add_compile_options(-Wextra)
2626
add_compile_options(-Wimplicit-procedure)
27-
add_compile_options(-Wconversion-extra)
2827
# -pedantic-errors triggers a false positive for optional arguments of elemental functions,
2928
# see test_optval and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95446
3029
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.0)

config/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ endif()
1313
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1414
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
1515

16+
# Check for available features
17+
# Note: users can overwrite the automatic check by setting the value at configure time
18+
include(CheckFortranSourceRuns)
19+
if (NOT DEFINED WITH_QP)
20+
check_fortran_source_runs(
21+
"if (selected_real_kind(33) == -1) stop 1; end"
22+
WITH_QP
23+
)
24+
endif()
25+
if (NOT DEFINED WITH_XDP)
26+
set(WITH_QP ${WITH_QP} PARENT_SCOPE)
27+
check_fortran_source_runs(
28+
"if (any(selected_real_kind(18) == [-1, selected_real_kind(33)])) stop 1; end"
29+
WITH_XDP
30+
)
31+
set(WITH_XDP ${WITH_XDP} PARENT_SCOPE)
32+
endif()
33+
1634
# Export a pkg-config file
1735
configure_file(
1836
"${CMAKE_CURRENT_SOURCE_DIR}/template.pc"

config/template.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@PACKAGE_INIT@
22

3+
set("@PROJECT_NAME@_WITH_QP" @WITH_QP@)
4+
set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@)
5+
36
if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")
47
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
58
endif()

doc/specs/stdlib_kinds.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ The `stdlib_kinds` module provides kind parameters for the Fortran intrinsic dat
1616

1717
### `sp`
1818

19-
Alias for intrinsic named constant `real32` imported from `iso_fortran_env`.
19+
Provides real kind parameter for floating point numbers with a minimal precision of 6 significant digits.
2020

2121

2222
### `dp`
2323

24-
Alias for intrinsic named constant `real64` imported from `iso_fortran_env`.
24+
Provides real kind parameter for floating point numbers with a minimal precision of 15 significant digits.
25+
26+
27+
### `xdp`
28+
29+
Provides real kind parameter for floating point numbers with a minimal precision of 18 significant digits.
30+
If not available it has value `-1`.
2531

2632

2733
### `qp`
2834

29-
Alias for intrinsic named constant `real128` imported from `iso_fortran_env`.
35+
Provides real kind parameter for floating point numbers with a minimal precision of 33 significant digits.
36+
If not available it has value `-1`.
3037

3138

3239
### `int8`

src/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ else()
5050
set(fyppFlags "-DVERSION90")
5151
endif()
5252

53+
list(
54+
APPEND fyppFlags
55+
"-DWITH_QP=$<BOOL:${WITH_QP}>"
56+
"-DWITH_XDP=$<BOOL:${WITH_XDP}>"
57+
)
58+
5359
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
5460

5561
set(SRC

src/common.fypp

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
#:mute
22

3+
#! Support for quadruple precision floating point numbers
4+
#:if not defined("WITH_QP")
5+
#:set WITH_QP = 0
6+
#:endif
7+
8+
#! Support for extended double precision floating point numbers
9+
#:if not defined("WITH_XDP")
10+
#:set WITH_XDP = 0
11+
#:endif
12+
313
#! Real kinds to be considered during templating
4-
#:set REAL_KINDS = ["sp", "dp", "qp"]
14+
#:set REAL_KINDS = ["sp", "dp"]
15+
#:if WITH_XDP
16+
#:set REAL_KINDS = REAL_KINDS + ["xdp"]
17+
#:endif
18+
#:if WITH_QP
19+
#:set REAL_KINDS = REAL_KINDS + ["qp"]
20+
#:endif
521

622
#! Real types to be considered during templating
723
#:set REAL_TYPES = ["real({})".format(k) for k in REAL_KINDS]
@@ -10,7 +26,13 @@
1026
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES))
1127

1228
#! Complex kinds to be considered during templating
13-
#:set CMPLX_KINDS = ["sp", "dp", "qp"]
29+
#:set CMPLX_KINDS = ["sp", "dp"]
30+
#:if WITH_XDP
31+
#:set CMPLX_KINDS = CMPLX_KINDS + ["xdp"]
32+
#:endif
33+
#:if WITH_QP
34+
#:set CMPLX_KINDS = CMPLX_KINDS + ["qp"]
35+
#:endif
1436

1537
#! Complex types to be considered during templating
1638
#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS]

src/stdlib_io.fypp

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module stdlib_io
66
!! Provides a support for file handling
77
!! ([Specification](../page/specs/stdlib_io.html))
88

9-
use stdlib_kinds, only: sp, dp, qp, &
9+
use stdlib_kinds, only: sp, dp, xdp, qp, &
1010
int8, int16, int32, int64
1111
use stdlib_error, only: error_stop
1212
use stdlib_optval, only: optval
@@ -24,9 +24,11 @@ module stdlib_io
2424
FMT_INT = '(*(i0,1x))', &
2525
FMT_REAL_SP = '(*(es15.8e2,1x))', &
2626
FMT_REAL_DP = '(*(es24.16e3,1x))', &
27+
FMT_REAL_XDP = '(*(es26.18e3,1x))', &
2728
FMT_REAL_QP = '(*(es44.35e4,1x))', &
2829
FMT_COMPLEX_SP = '(*(es15.8e2,1x,es15.8e2))', &
2930
FMT_COMPLEX_DP = '(*(es24.16e3,1x,es24.16e3))', &
31+
FMT_COMPLEX_XDP = '(*(es26.18e3,1x,es26.18e3))', &
3032
FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))'
3133

3234
interface loadtxt

src/stdlib_kinds.f90

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
!> Version: experimental
2+
!>
3+
!> The specification of this module is available [here](../page/specs/stdlib_kinds.html).
14
module stdlib_kinds
2-
!! version: experimental
3-
use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128
4-
use iso_fortran_env, only: int8, int16, int32, int64
5-
use iso_c_binding, only: c_bool
6-
! If we decide later to use iso_c_binding instead of iso_fortran_env:
7-
!use iso_c_binding, only: sp=>c_float, dp=>c_double, qp=>c_float128
8-
!use iso_c_binding, only: int8=>c_int8_t, int16=>c_int16_t, int32=>c_int32_t, int64=>c_int64_t
9-
implicit none
10-
private
11-
public sp, dp, qp, int8, int16, int32, int64, lk, c_bool
12-
13-
integer, parameter :: lk = kind(.true.)
5+
use iso_fortran_env, only: int8, int16, int32, int64
6+
use iso_c_binding, only: c_bool
7+
implicit none
8+
private
9+
public :: sp, dp, xdp, qp, int8, int16, int32, int64, lk, c_bool
10+
11+
!> Single precision real numbers
12+
integer, parameter :: sp = selected_real_kind(6)
13+
14+
!> Double precision real numbers
15+
integer, parameter :: dp = selected_real_kind(15)
16+
17+
!> Extended double precision real numbers
18+
integer, parameter :: xdp = selected_real_kind(18)
19+
20+
!> Quadruple precision real numbers
21+
integer, parameter :: qp = selected_real_kind(33)
22+
23+
!> Default logical kind parameter
24+
integer, parameter :: lk = kind(.true.)
25+
1426
end module stdlib_kinds

src/stdlib_linalg.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module stdlib_linalg
44
!!Provides a support for various linear algebra procedures
55
!! ([Specification](../page/specs/stdlib_linalg.html))
6-
use stdlib_kinds, only: sp, dp, qp, &
6+
use stdlib_kinds, only: sp, dp, xdp, qp, &
77
int8, int16, int32, int64
88
use stdlib_optval, only: optval
99
implicit none

src/stdlib_math.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
44

55
module stdlib_math
6-
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
6+
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
77
use stdlib_optval, only: optval
88

99
implicit none

src/stdlib_optval.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module stdlib_optval
1616
!!
1717
!! It is an error to call `optval` with a single actual argument.
1818
!!
19-
use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64
19+
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
2020
implicit none
2121

2222

src/stdlib_quadrature.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#:include "common.fypp"
22
module stdlib_quadrature
33
!! ([Specification](../page/specs/stdlib_quadrature.html#description))
4-
use stdlib_kinds, only: sp, dp, qp
4+
use stdlib_kinds, only: sp, dp, xdp, qp
55

66
implicit none
77

src/stdlib_sorting.fypp

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ module stdlib_sorting
121121
int64, &
122122
sp, &
123123
dp, &
124+
xdp, &
124125
qp
125126

126127
use stdlib_optval, only: optval

src/stdlib_specialfunctions.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module stdlib_specialfunctions
2-
use stdlib_kinds, only: sp, dp, qp
2+
use stdlib_kinds, only: sp, dp, xdp, qp
33

44
implicit none
55

src/stdlib_stats.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module stdlib_stats
77
!! Provides support for various statistical methods. This includes currently
88
!! descriptive statistics
99
!! ([Specification](../page/specs/stdlib_stats.html))
10-
use stdlib_kinds, only: sp, dp, qp, &
10+
use stdlib_kinds, only: sp, dp, xdp, qp, &
1111
int8, int16, int32, int64
1212
implicit none
1313
private

src/stdlib_strings.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module stdlib_strings
77
use stdlib_ascii, only: whitespace
88
use stdlib_string_type, only: string_type, char, verify, repeat, len
99
use stdlib_optval, only: optval
10-
use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64, lk, c_bool
10+
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64, lk, c_bool
1111
implicit none
1212
private
1313

src/tests/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ macro(ADDTEST name)
1010
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1111
endmacro(ADDTEST)
1212

13+
list(
14+
APPEND fyppFlags
15+
"-I${PROJECT_SOURCE_DIR}/src"
16+
)
17+
1318
add_subdirectory(ascii)
1419
add_subdirectory(bitsets)
1520
add_subdirectory(io)

src/tests/io/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
set(
2+
fppFiles
3+
"test_loadtxt_qp.fypp"
4+
"test_savetxt_qp.fypp"
5+
)
6+
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
7+
18
ADDTEST(loadtxt)
29
ADDTEST(savetxt)
310

src/tests/io/Makefile.manual

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
SRCFYPP = \
2+
test_loadtxt_qp.fypp \
3+
test_savetxt_qp.fypp
4+
15
PROGS_SRC = test_loadtxt.f90 \
26
test_savetxt.f90 \
3-
test_loadtxt_qp.f90 \
4-
test_savetxt_qp.f90 \
57
test_parse_mode.f90 \
6-
test_open.f90
8+
test_open.f90 \
9+
$(SRCFYPP:.fypp=.f90)
10+
11+
$(SRCFYPP): %.f90: %.fypp ../../common.fypp
12+
fypp -I../.. $(FYPPFLAGS) $< $@
713

814
CLEAN_FILES = tmp*.dat io_open.dat io_open.stream
915

src/tests/io/test_loadtxt_qp.f90 renamed to src/tests/io/test_loadtxt_qp.fypp

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#:include "common.fypp"
2+
13
module test_loadtxt_qp
24
use stdlib_kinds, only: qp
35
use stdlib_io, only: loadtxt, savetxt
@@ -25,6 +27,7 @@ end subroutine collect_loadtxt_qp
2527
subroutine test_loadtxt_qp_(error)
2628
!> Error handling
2729
type(error_type), allocatable, intent(out) :: error
30+
#:if WITH_QP
2831
real(qp), allocatable :: input(:,:), expected(:,:)
2932
integer :: n
3033

@@ -39,13 +42,17 @@ subroutine test_loadtxt_qp_(error)
3942
call check(error, all(input == expected))
4043
if (allocated(error)) return
4144
end do
45+
#:else
46+
call skip_test(error, "Quadruple precision is not enabled")
47+
#:endif
4248

4349
end subroutine test_loadtxt_qp_
4450

4551

4652
subroutine test_loadtxt_qp_huge(error)
4753
!> Error handling
4854
type(error_type), allocatable, intent(out) :: error
55+
#:if WITH_QP
4956
real(qp), allocatable :: input(:,:), expected(:,:)
5057
integer :: n
5158

@@ -60,13 +67,17 @@ subroutine test_loadtxt_qp_huge(error)
6067
call check(error, all(input == expected))
6168
if (allocated(error)) return
6269
end do
70+
#:else
71+
call skip_test(error, "Quadruple precision is not enabled")
72+
#:endif
6373

6474
end subroutine test_loadtxt_qp_huge
6575

6676

6777
subroutine test_loadtxt_qp_tiny(error)
6878
!> Error handling
6979
type(error_type), allocatable, intent(out) :: error
80+
#:if WITH_QP
7081
real(qp), allocatable :: input(:,:), expected(:,:)
7182
integer :: n
7283

@@ -81,6 +92,9 @@ subroutine test_loadtxt_qp_tiny(error)
8192
call check(error, all(input == expected))
8293
if (allocated(error)) return
8394
end do
95+
#:else
96+
call skip_test(error, "Quadruple precision is not enabled")
97+
#:endif
8498

8599
end subroutine test_loadtxt_qp_tiny
86100

src/tests/io/test_savetxt_qp.f90 renamed to src/tests/io/test_savetxt_qp.fypp

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#:include "common.fypp"
2+
13
module test_savetxt_qp
24
use stdlib_kinds, only: qp
35
use stdlib_io, only: loadtxt, savetxt
@@ -38,6 +40,7 @@ end function get_outpath
3840
subroutine test_rqp(error)
3941
!> Error handling
4042
type(error_type), allocatable, intent(out) :: error
43+
#:if WITH_QP
4144
real(qp) :: d(3, 2), e(2, 3)
4245
real(qp), allocatable :: d2(:, :)
4346
character(:), allocatable :: outpath
@@ -59,12 +62,16 @@ subroutine test_rqp(error)
5962
if (allocated(error)) return
6063
call check(error, all(e == d2))
6164
if (allocated(error)) return
65+
#:else
66+
call skip_test(error, "Quadruple precision is not enabled")
67+
#:endif
6268
end subroutine test_rqp
6369

6470

6571
subroutine test_cqp(error)
6672
!> Error handling
6773
type(error_type), allocatable, intent(out) :: error
74+
#:if WITH_QP
6875
complex(qp) :: d(3, 2), e(2, 3)
6976
complex(qp), allocatable :: d2(:, :)
7077
character(:), allocatable :: outpath
@@ -86,6 +93,9 @@ subroutine test_cqp(error)
8693
if (allocated(error)) return
8794
call check(error, all(e == d2))
8895
if (allocated(error)) return
96+
#:else
97+
call skip_test(error, "Quadruple precision is not enabled")
98+
#:endif
8999
end subroutine test_cqp
90100

91101
end module test_savetxt_qp

0 commit comments

Comments
 (0)