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 1 commit
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`.


### `lp`

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))

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

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

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

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

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, lp, c_bool

integer, parameter :: lp = kind(.true.)
end module stdlib_kinds
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, lp, 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._lp
call check(to_string(.false._lp) == trim(flc))
end subroutine test_to_string

end program test_ascii