Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add stdlib_experimental_kinds.f90 and use it
  • Loading branch information
certik committed Jan 5, 2020
commit 4a52299a9e1cf1f1c9c73d229d2eab99a43f4c7d
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(SRC
stdlib_experimental_io.f90
stdlib_experimental_error.f90
stdlib_experimental_optval.f90
stdlib_experimental_kinds.f90
)

add_library(fortran_stdlib ${SRC})
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib_experimental_io.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module stdlib_experimental_io
use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128
use stdlib_experimental_kinds, only: sp, dp, qp
use stdlib_experimental_error, only: error_stop
use stdlib_experimental_optval, only: optval
implicit none
Expand Down
10 changes: 10 additions & 0 deletions src/stdlib_experimental_kinds.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module stdlib_experimental_kinds
! Instead of iso_fortran_env, we use iso_c_binding, to be compatible with C
!use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128
!use iso_fortran_env, only: int32, int64, int128
use iso_c_binding, only: sp=>c_float, dp=>c_double, qp=>c_float128
use iso_c_binding, only: int32=>c_int32_t, int64=>c_int64_t, int128=>c_int128_t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is int128 supported by all compilers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. If C has standardized int128 I would image that it is. But I need to consult the standard for more insight.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least I don't find c_int128_t in iso_c_binding or int128iniso_fortran_env`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it compiled. It might be only supported by gfortran?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard says that it will compile, but be set to a special value when not supported (missing) if my memory is correct. So compilation doesn't guarantee existence of the kind. (I think the special value is 0 or a negative integer.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like C99 has no guaranteed 128-bit integer (long long is "at least 64 bits" and intN_t is only guaranteed up to 64).

Looking at my own include files (libc 2.30), I don't see anything for 128-bit integers except a few places under an __ILP32__ preprocessor flag, which must have been unset when my platform-specific includes were preprocessed for my system.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think one does need to be careful with quad precision. On its own, it does not have a clear meaning. There are (at least) three active definitions:

https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html

For example, on my machine, double and long double both point to _Float64. My libc also defines a _Float64x which as best I can tell corresponds to the x86 float80 format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I am looking at a copy of the 2018 standard now (Table 18.2 in section 18.3.1), and I don't see any reference to c_int128_t in there? Only up to c_int64_t. Also no reference to c_float128.

implicit none
private
public sp, dp, qp, int32, int64, int128
end module
2 changes: 1 addition & 1 deletion src/tests/io/test_loadtxt.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program test_loadtxt
use iso_fortran_env, only: sp=>real32, dp=>real64
use stdlib_experimental_kinds, only: sp, dp
use stdlib_experimental_io, only: loadtxt
use stdlib_experimental_error, only: error_stop
implicit none
Expand Down
2 changes: 1 addition & 1 deletion src/tests/io/test_loadtxt_qp.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program test_loadtxt_qp
use iso_fortran_env, only: qp=>real128
use stdlib_experimental_kinds, only: qp
use stdlib_experimental_io, only: loadtxt
implicit none

Expand Down
2 changes: 1 addition & 1 deletion src/tests/io/test_savetxt.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program test_savetxt
use iso_fortran_env, only: sp=>real32, dp=>real64
use stdlib_experimental_kinds, only: sp, dp
use stdlib_experimental_io, only: loadtxt, savetxt
use stdlib_experimental_error, only: assert
implicit none
Expand Down
2 changes: 1 addition & 1 deletion src/tests/io/test_savetxt_qp.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program test_savetxt_qp
use iso_fortran_env, only: qp=>real128
use stdlib_experimental_kinds, only: qp
use stdlib_experimental_io, only: loadtxt, savetxt
use stdlib_experimental_error, only: assert
implicit none
Expand Down