|
| 1 | +!===-- module/__fortran_ieee_exceptions.f90 --------------------------------===! |
| 2 | +! |
| 3 | +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +! See https://llvm.org/LICENSE.txt for license information. |
| 5 | +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +! |
| 7 | +!===------------------------------------------------------------------------===! |
| 8 | + |
| 9 | +! See Fortran 2018, clause 17 |
| 10 | +! The content of the standard intrinsic IEEE_EXCEPTIONS module is packaged |
| 11 | +! here under another name so that IEEE_ARITHMETIC can USE it and export its |
| 12 | +! declarations without clashing with a non-intrinsic module in a program. |
| 13 | + |
| 14 | +module __Fortran_ieee_exceptions |
| 15 | + |
| 16 | + type :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3 |
| 17 | + private |
| 18 | + integer(kind=1) :: flag = 0 |
| 19 | + end type ieee_flag_type |
| 20 | + |
| 21 | + type(ieee_flag_type), parameter :: & |
| 22 | + ieee_invalid = ieee_flag_type(1), & |
| 23 | + ieee_overflow = ieee_flag_type(2), & |
| 24 | + ieee_divide_by_zero = ieee_flag_type(4), & |
| 25 | + ieee_underflow = ieee_flag_type(8), & |
| 26 | + ieee_inexact = ieee_flag_type(16), & |
| 27 | + ieee_denorm = ieee_flag_type(32) ! PGI extension |
| 28 | + |
| 29 | + type(ieee_flag_type), parameter :: & |
| 30 | + ieee_usual(*) = [ & |
| 31 | + ieee_overflow, ieee_divide_by_zero, ieee_invalid ], & |
| 32 | + ieee_all(*) = [ & |
| 33 | + ieee_usual, ieee_underflow, ieee_inexact, ieee_denorm ] |
| 34 | + |
| 35 | + type :: ieee_modes_type ! Fortran 2018, 17.7 |
| 36 | + private |
| 37 | + end type ieee_modes_type |
| 38 | + |
| 39 | + type :: ieee_status_type ! Fortran 2018, 17.7 |
| 40 | + private |
| 41 | + end type ieee_status_type |
| 42 | + |
| 43 | + private :: ieee_support_flag_2, ieee_support_flag_3, & |
| 44 | + ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, & |
| 45 | + ieee_support_flag_16 |
| 46 | + interface ieee_support_flag |
| 47 | + module procedure :: ieee_support_flag, & |
| 48 | + ieee_support_flag_2, ieee_support_flag_3, & |
| 49 | + ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, & |
| 50 | + ieee_support_flag_16 |
| 51 | + end interface |
| 52 | + |
| 53 | + contains |
| 54 | + elemental subroutine ieee_get_flag(flag, flag_value) |
| 55 | + type(ieee_flag_type), intent(in) :: flag |
| 56 | + logical, intent(out) :: flag_value |
| 57 | + end subroutine ieee_get_flag |
| 58 | + |
| 59 | + elemental subroutine ieee_get_halting_mode(flag, halting) |
| 60 | + type(ieee_flag_type), intent(in) :: flag |
| 61 | + logical, intent(out) :: halting |
| 62 | + end subroutine ieee_get_halting_mode |
| 63 | + |
| 64 | + subroutine ieee_get_modes(modes) |
| 65 | + type(ieee_modes_type), intent(out) :: modes |
| 66 | + end subroutine ieee_get_modes |
| 67 | + |
| 68 | + subroutine ieee_get_status(status) |
| 69 | + type(ieee_status_type), intent(out) :: status |
| 70 | + end subroutine ieee_get_status |
| 71 | + |
| 72 | + pure subroutine ieee_set_flag(flag, flag_value) |
| 73 | + type(ieee_flag_type), intent(in) :: flag |
| 74 | + logical, intent(in) :: flag_value |
| 75 | + end subroutine ieee_set_flag |
| 76 | + |
| 77 | + pure subroutine ieee_set_halting_mode(flag, halting) |
| 78 | + type(ieee_flag_type), intent(in) :: flag |
| 79 | + logical, intent(in) :: halting |
| 80 | + end subroutine ieee_set_halting_mode |
| 81 | + |
| 82 | + subroutine ieee_set_modes(modes) |
| 83 | + type(ieee_modes_type), intent(in) :: modes |
| 84 | + end subroutine ieee_set_modes |
| 85 | + |
| 86 | + subroutine ieee_set_status(status) |
| 87 | + type(ieee_status_type), intent(in) :: status |
| 88 | + end subroutine ieee_set_status |
| 89 | + |
| 90 | + pure logical function ieee_support_flag(flag) |
| 91 | + type(ieee_flag_type), intent(in) :: flag |
| 92 | + ieee_support_flag = .true. |
| 93 | + end function |
| 94 | + pure logical function ieee_support_flag_2(flag, x) |
| 95 | + type(ieee_flag_type), intent(in) :: flag |
| 96 | + real(kind=2), intent(in) :: x(..) |
| 97 | + ieee_support_flag_2 = .true. |
| 98 | + end function |
| 99 | + pure logical function ieee_support_flag_3(flag, x) |
| 100 | + type(ieee_flag_type), intent(in) :: flag |
| 101 | + real(kind=3), intent(in) :: x(..) |
| 102 | + ieee_support_flag_3 = .true. |
| 103 | + end function |
| 104 | + pure logical function ieee_support_flag_4(flag, x) |
| 105 | + type(ieee_flag_type), intent(in) :: flag |
| 106 | + real(kind=4), intent(in) :: x(..) |
| 107 | + ieee_support_flag_4 = .true. |
| 108 | + end function |
| 109 | + pure logical function ieee_support_flag_8(flag, x) |
| 110 | + type(ieee_flag_type), intent(in) :: flag |
| 111 | + real(kind=8), intent(in) :: x(..) |
| 112 | + ieee_support_flag_8 = .true. |
| 113 | + end function |
| 114 | + pure logical function ieee_support_flag_10(flag, x) |
| 115 | + type(ieee_flag_type), intent(in) :: flag |
| 116 | + real(kind=10), intent(in) :: x(..) |
| 117 | + ieee_support_flag_10 = .true. |
| 118 | + end function |
| 119 | + pure logical function ieee_support_flag_16(flag, x) |
| 120 | + type(ieee_flag_type), intent(in) :: flag |
| 121 | + real(kind=16), intent(in) :: x(..) |
| 122 | + ieee_support_flag_16 = .true. |
| 123 | + end function |
| 124 | + |
| 125 | + pure logical function ieee_support_halting(flag) |
| 126 | + type(ieee_flag_type), intent(in) :: flag |
| 127 | + end function ieee_support_halting |
| 128 | + |
| 129 | +end module __Fortran_ieee_exceptions |
0 commit comments