selected_real_kind.f90 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ! Copyright (C) 2003-2015 Free Software Foundation, Inc.
  2. ! Contributed by Kejia Zhao <kejia_zh@yahoo.com.cn>
  3. !
  4. !This file is part of the GNU Fortran runtime library (libgfortran).
  5. !
  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.
  10. !
  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.
  15. !
  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.
  19. !
  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/>.
  24. function _gfortran_selected_real_kind2008 (p, r, rdx)
  25. implicit none
  26. integer, optional, intent (in) :: p, r, rdx
  27. integer :: _gfortran_selected_real_kind2008
  28. integer :: i, p2, r2, radix2
  29. logical :: found_p, found_r, found_radix
  30. ! Real kind_precision_range table
  31. type :: real_info
  32. integer :: kind
  33. integer :: precision
  34. integer :: range
  35. integer :: radix
  36. end type real_info
  37. include "selected_real_kind.inc"
  38. _gfortran_selected_real_kind2008 = 0
  39. p2 = 0
  40. r2 = 0
  41. radix2 = 0
  42. found_p = .false.
  43. found_r = .false.
  44. found_radix = .false.
  45. if (present (p)) p2 = p
  46. if (present (r)) r2 = r
  47. if (present (rdx)) radix2 = rdx
  48. ! Assumes each type has a greater precision and range than previous one.
  49. do i = 1, c
  50. if (p2 <= real_infos (i) % precision) found_p = .true.
  51. if (r2 <= real_infos (i) % range) found_r = .true.
  52. if (radix2 <= real_infos (i) % radix) found_radix = .true.
  53. if (p2 <= real_infos (i) % precision &
  54. .and. r2 <= real_infos (i) % range &
  55. .and. radix2 <= real_infos (i) % radix) then
  56. _gfortran_selected_real_kind2008 = real_infos (i) % kind
  57. return
  58. end if
  59. end do
  60. if (found_radix .and. found_r .and. .not. found_p) then
  61. _gfortran_selected_real_kind2008 = -1
  62. elseif (found_radix .and. found_p .and. .not. found_r) then
  63. _gfortran_selected_real_kind2008 = -2
  64. elseif (found_radix .and. .not. found_p .and. .not. found_r) then
  65. _gfortran_selected_real_kind2008 = -3
  66. elseif (found_radix) then
  67. _gfortran_selected_real_kind2008 = -4
  68. else
  69. _gfortran_selected_real_kind2008 = -5
  70. end if
  71. end function _gfortran_selected_real_kind2008
  72. function _gfortran_selected_real_kind (p, r)
  73. implicit none
  74. integer, optional, intent (in) :: p, r
  75. integer :: _gfortran_selected_real_kind
  76. interface
  77. function _gfortran_selected_real_kind2008 (p, r, rdx)
  78. implicit none
  79. integer, optional, intent (in) :: p, r, rdx
  80. integer :: _gfortran_selected_real_kind2008
  81. end function _gfortran_selected_real_kind2008
  82. end interface
  83. _gfortran_selected_real_kind = _gfortran_selected_real_kind2008 (p, r)
  84. end function