1 ! Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 ! Contributed by Kejia Zhao <kejia_zh@yahoo.com.cn>
4 !This file is part of the GNU Fortran runtime library (libgfortran).
6 !Libgfortran is free software; you can redistribute it and/or
7 !modify it under the terms of the GNU General Public
8 !License as published by the Free Software Foundation; either
9 !version 3 of the License, or (at your option) any later version.
11 !Libgfortran is distributed in the hope that it will be useful,
12 !but WITHOUT ANY WARRANTY; without even the implied warranty of
13 !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 !GNU General Public License for more details.
16 !Under Section 7 of GPL version 3, you are granted additional
17 !permissions described in the GCC Runtime Library Exception, version
18 !3.1, as published by the Free Software Foundation.
20 !You should have received a copy of the GNU General Public License and
21 !a copy of the GCC Runtime Library Exception along with this program;
22 !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 !<http://www.gnu.org/licenses/>.
25 function _gfortran_selected_real_kind2008 (p
, r
, rdx
)
27 integer, optional
, intent (in
) :: p
, r
, rdx
28 integer :: _gfortran_selected_real_kind2008
29 integer :: i
, p2
, r2
, radix2
30 logical :: found_p
, found_r
, found_radix
31 ! Real kind_precision_range table
39 include "selected_real_kind.inc"
41 _gfortran_selected_real_kind2008
= 0
49 if (present (p
)) p2
= p
50 if (present (r
)) r2
= r
51 if (present (rdx
)) radix2
= rdx
53 ! Assumes each type has a greater precision and range than previous one.
56 if (p2
<= real_infos (i
) % precision) found_p
= .true
.
57 if (r2
<= real_infos (i
) % range
) found_r
= .true
.
58 if (radix2
<= real_infos (i
) % radix
) found_radix
= .true
.
60 if (p2
<= real_infos (i
) % precision &
61 .and
. r2
<= real_infos (i
) % range
&
62 .and
. radix2
<= real_infos (i
) % radix
) then
63 _gfortran_selected_real_kind2008
= real_infos (i
) % kind
68 if (found_radix
.and
. found_r
.and
. .not
. found_p
) then
69 _gfortran_selected_real_kind2008
= -1
70 elseif (found_radix
.and
. found_p
.and
. .not
. found_r
) then
71 _gfortran_selected_real_kind2008
= -2
72 elseif (found_radix
.and
. .not
. found_p
.and
. .not
. found_r
) then
73 _gfortran_selected_real_kind2008
= -3
74 elseif (found_radix
) then
75 _gfortran_selected_real_kind2008
= -4
77 _gfortran_selected_real_kind2008
= -5
79 end function _gfortran_selected_real_kind2008
81 function _gfortran_selected_real_kind (p
, r
)
83 integer, optional
, intent (in
) :: p
, r
84 integer :: _gfortran_selected_real_kind
87 function _gfortran_selected_real_kind2008 (p
, r
, rdx
)
89 integer, optional
, intent (in
) :: p
, r
, rdx
90 integer :: _gfortran_selected_real_kind2008
91 end function _gfortran_selected_real_kind2008
94 _gfortran_selected_real_kind
= _gfortran_selected_real_kind2008 (p
, r
)