Skip to content

Add separate logical kind parameters #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions doc/specs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
- [error](./stdlib_error.html) - Catching and handling errors
- [IO](./stdlib_io.html) - Input/output helper & convenience
- [kinds](./stdlib_kinds.html) - Kind parameters
- [linalg](./stdlib_linalg.html) - Linear Algebra
- [logger](./stdlib_logger.html) - Runtime logging system
- [optval](./stdlib_optval.html) - Fallback value for optional arguments
Expand All @@ -25,10 +26,6 @@ This is and index/directory of the specifications (specs) for each new module/fe
- [string\_type](./stdlib_string_type.html) - Basic string support
- [strings](./stdlib_strings.html) - String handling and manipulation routines

## Missing specs

- [kinds](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_kinds.f90)

## Released/Stable Features & Modules

- (None yet)
59 changes: 59 additions & 0 deletions doc/specs/stdlib_kinds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: kinds
---

# The `stdlib_kinds` module

[TOC]

## Introduction

The `stdlib_kinds` module provides kind parameters for the Fortran intrinsic data types,
*integer*, *logical*, *real*, and *complex*.


## Constants provided by `stdlib_kinds`

### `sp`

Alias for intrinsic named constant `real32` imported from `iso_fortran_env`.


### `dp`

Alias for intrinsic named constant `real64` imported from `iso_fortran_env`.


### `qp`

Alias for intrinsic named constant `real128` imported from `iso_fortran_env`.


### `int8`

Reexported intrinsic named constant `int8` from `iso_fortran_env`.


### `int16`

Reexported intrinsic named constant `int16` from `iso_fortran_env`.


### `int32`

Reexported intrinsic named constant `int32` from `iso_fortran_env`.


### `int64`

Reexported intrinsic named constant `int64` from `iso_fortran_env`.


### `lk`

Kind parameter of the default logical data type.


### `c_bool`

Reexported intrinsic named constant `c_bool` from `iso_c_binding`.
9 changes: 9 additions & 0 deletions src/common.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#! Collected (kind, type) tuples for integer types
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES))

#! Logical kinds to be considered during templating
#:set LOG_KINDS = ["lk", "c_bool"]

#! Logical types to be considered during templating
#:set LOG_TYPES = ["logical({})".format(k) for k in LOG_KINDS]

#! Collected (kind, type) tuples for logical types
#:set LOG_KINDS_TYPES = list(zip(LOG_KINDS, LOG_TYPES))

#! Derived type string_type
#:set STRING_KINDS = ["string_type"]

Expand Down
6 changes: 4 additions & 2 deletions src/stdlib_ascii.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!>
!> The specification of this module is available [here](../page/specs/stdlib_ascii.html).
module stdlib_ascii
use stdlib_kinds, only : int8, int16, int32, int64
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool

implicit none
private
Expand All @@ -28,6 +28,8 @@ module stdlib_ascii
interface to_string
#:for kind in INT_KINDS
module procedure :: to_string_integer_${kind}$
#:endfor
#:for kind in LOG_KINDS
module procedure :: to_string_logical_${kind}$
#:endfor
end interface to_string
Expand Down Expand Up @@ -396,7 +398,7 @@ contains
end function to_string_integer_${kind}$
#:endfor

#:for kind in INT_KINDS
#:for kind in LOG_KINDS
!> Represent an logical of kind ${kind}$ as character sequence
pure function to_string_logical_${kind}$(val) result(string)
integer, parameter :: ik = ${kind}$
Expand Down
5 changes: 4 additions & 1 deletion src/stdlib_kinds.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ module stdlib_kinds
!! version: experimental
use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128
use iso_fortran_env, only: int8, int16, int32, int64
use iso_c_binding, only: c_bool
! If we decide later to use iso_c_binding instead of iso_fortran_env:
!use iso_c_binding, only: sp=>c_float, dp=>c_double, qp=>c_float128
!use iso_c_binding, only: int8=>c_int8_t, int16=>c_int16_t, int32=>c_int32_t, int64=>c_int64_t
implicit none
private
public sp, dp, qp, int8, int16, int32, int64
public sp, dp, qp, int8, int16, int32, int64, lk, c_bool

integer, parameter :: lk = kind(.true.)
end module stdlib_kinds
6 changes: 4 additions & 2 deletions src/stdlib_string_type.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
module stdlib_string_type
use stdlib_ascii, only: to_lower_ => to_lower, to_upper_ => to_upper, &
& to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse, to_string
use stdlib_kinds, only : int8, int16, int32, int64
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
implicit none
private

Expand Down Expand Up @@ -47,6 +47,8 @@ module stdlib_string_type
module procedure :: new_string
#:for kind in INT_KINDS
module procedure :: new_string_from_integer_${kind}$
#:endfor
#:for kind in LOG_KINDS
module procedure :: new_string_from_logical_${kind}$
#:endfor
end interface string_type
Expand Down Expand Up @@ -373,7 +375,7 @@ contains
end function new_string_from_integer_${kind}$
#:endfor

#:for kind in INT_KINDS
#:for kind in LOG_KINDS
!> Constructor for new string instances from a logical of kind ${kind}$.
elemental function new_string_from_logical_${kind}$(val) result(new)
logical(${kind}$), intent(in) :: val
Expand Down
10 changes: 5 additions & 5 deletions src/tests/ascii/test_ascii.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ program test_ascii
is_control, is_punctuation, is_graphical, is_printable, is_ascii, &
to_lower, to_upper, to_title, to_sentence, reverse, LF, TAB, NUL, DEL, &
to_string
use stdlib_kinds, only : int8, int16, int32, int64
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool

implicit none

Expand Down Expand Up @@ -676,11 +676,11 @@ subroutine test_to_string
write(flc, '(g0)') .false.
call check(to_string(.false.) == trim(flc))

write(flc, '(g0)') .true._int8
call check(to_string(.true._int8) == trim(flc))
write(flc, '(g0)') .true._c_bool
call check(to_string(.true._c_bool) == trim(flc))

write(flc, '(g0)') .false._int64
call check(to_string(.false._int64) == trim(flc))
write(flc, '(g0)') .false._lk
call check(to_string(.false._lk) == trim(flc))
end subroutine test_to_string

end program test_ascii
10 changes: 5 additions & 5 deletions src/tests/string/test_string_assignment.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
! SPDX-Identifier: MIT
module test_string_assignment
use stdlib_error, only : check
use stdlib_kinds, only : int8, int16, int32, int64
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
use stdlib_string_type, only : string_type, assignment(=), operator(==), len
implicit none

Expand Down Expand Up @@ -52,11 +52,11 @@ subroutine test_char_value
write(flc, '(g0)') .false.
call check(string_type(.false.) == trim(flc))

write(flc, '(g0)') .false._int8
call check(string_type(.false._int8) == trim(flc))
write(flc, '(g0)') .false._c_bool
call check(string_type(.false._c_bool) == trim(flc))

write(flc, '(g0)') .true._int64
call check(string_type(.true._int64) == trim(flc))
write(flc, '(g0)') .true._lk
call check(string_type(.true._lk) == trim(flc))
end subroutine test_char_value

end module test_string_assignment
Expand Down