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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 18 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 10 additions & 3 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 24 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 24 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)