|
| 1 | +To: J3 J3/##-### |
| 2 | +From: Patrick Fasano |
| 3 | +Subject: Requirements and specifications for interoperability with C |
| 4 | + interchange and extended types |
| 5 | +Date: 2025-Oct-XX |
| 6 | + |
| 7 | +References: |
| 8 | + ISO/IEC 9899:2024 Programming languages -- C ("C23") |
| 9 | + (working draft N3220) |
| 10 | + WG5/N2249 Fortran 202Y Work Items |
| 11 | + 23-176 Add extended floating-point types defined in ISO C23 |
| 12 | + to ISO_C_BINDING |
| 13 | + ISO/IEC 60559:2020 Floating-Point arithmetic |
| 14 | + IEEE 754-2019 IEEE Standard for Floating-Point Arithmetic |
| 15 | + |
| 16 | + |
| 17 | +1 Background |
| 18 | +============ |
| 19 | + |
| 20 | +bg01. The ISO C23 specification (ISO/IEC 9899:2024) added support for |
| 21 | + interchange and extended floating-point types (C23 Annex H). The |
| 22 | + current Fortran 202Y work list WG5/N2249 includes adding |
| 23 | + interoperability with these types as accepted work item US05. At |
| 24 | + meeting #230 in June 2023, J3 accepted paper 23-176 as |
| 25 | + background/use-case for additional interchange types. |
| 26 | + |
| 27 | +bg03. This paper contains formal requirements and specifications for |
| 28 | + Fortran 202Y proposal US05, "Add extended floating-point types |
| 29 | + defined in ISO C23 to ISO_C_BINDING". |
| 30 | + |
| 31 | +2 Requirements |
| 32 | +============== |
| 33 | + |
| 34 | +rq01. The C23 standard adds a large number of new types, importing |
| 35 | + significant portions of ISO/IEC 60559 (a.k.a IEEE 754) into its |
| 36 | + specification. The most important of these for Fortran |
| 37 | + interoperability with C are the '_Float16', '_Float32', |
| 38 | + '_Float64', and '_Float128' types (and their related complex |
| 39 | + types). Requirements rq02-r05 deal with these new types. Many of |
| 40 | + the other types, covered by rq07-rq17, are marked as optional and |
| 41 | + could be dropped independently while keeping the rest of this |
| 42 | + paper. These optional requirements primarily serve to maintain |
| 43 | + parity with Annex H of C23. |
| 44 | + |
| 45 | +rq02. The ISO_C_BINDING module should provide integer named constants |
| 46 | + for KIND parameters corresponding to the C interchange floating |
| 47 | + types '_Float16', '_Float32', '_Float64', and '_Float128'. |
| 48 | + |
| 49 | +rq03. If the companion processor defines '__STDC_IEC_60559_BFP__' and |
| 50 | + '__STDC_IEC_60559_TYPES__', then the KIND parameters corresponding |
| 51 | + to '_Float32' and '_Float64' should equal those corresponding to |
| 52 | + 'float' and 'double', respectively. |
| 53 | + |
| 54 | +rq05. The ISO_C_BINDING module should provide integer named constants |
| 55 | + for KIND parameters corresponding to the C interchange complex |
| 56 | + types '_Float16_Complex', '_Float32_Complex', '_Float64_Complex', |
| 57 | + and '_Float128_Complex'. The values of the named constants should |
| 58 | + equal those of the respective constants for the interchange |
| 59 | + floating types. |
| 60 | + |
| 61 | +rq07. The ISO_C_BINDING module should provide integer named constants |
| 62 | + for KIND parameters corresponding to the C extended floating types |
| 63 | + '_Float32x', '_Float64x', and '_Float128x'. |
| 64 | + |
| 65 | +rq09. The ISO_C_BINDING module should provide integer named constants |
| 66 | + for KIND parameters corresponding to the C extended complex types |
| 67 | + '_Float32x_Complex', '_Float64x_Complex', and |
| 68 | + '_Float128x_Complex'. The values of the named constants should |
| 69 | + match those of the respective constants for the extended floating |
| 70 | + types. |
| 71 | + |
| 72 | +rq11. The ISO_C_BINDING module should provide integer named constants |
| 73 | + for KIND parameters corresponding to the C interchange decimal |
| 74 | + floating types '_Decimal32', '_Decimal64', and '_Decimal128'. |
| 75 | + |
| 76 | +3 Specifications |
| 77 | +================ |
| 78 | + |
| 79 | +sp01. For all integer named constants to be added to the ISO_C_BINDING |
| 80 | + module, the value shall be a valid real kind type parameter or |
| 81 | + shall be -1 if the companion processor’s type does not have a |
| 82 | + precision equal to the precision of any of the Fortran processor’s |
| 83 | + real kinds, −2 if the companion processor’s type does not have a |
| 84 | + range equal to the range of any of the Fortran processor’s real |
| 85 | + kinds, −3 if the companion processor's type has neither the |
| 86 | + precision nor range of any of the Fortran processor’s real kinds, |
| 87 | + −4 if there is no interoperating Fortran processor kind for other |
| 88 | + reasons, and -5 if the companion processor does not define the |
| 89 | + corresponding C type. |
| 90 | + |
| 91 | +sp02. To the ISO_C_BINDING module, add the following integer named |
| 92 | + constants for real KIND parameters: |
| 93 | + |
| 94 | + +----------------+--------------------+ |
| 95 | + | Named constant | C interchange type | |
| 96 | + +----------------+--------------------+ |
| 97 | + | C_FLOAT16 | _Float16 | |
| 98 | + | C_FLOAT32 | _Float32 | |
| 99 | + | C_FLOAT64 | _Float64 | |
| 100 | + | C_FLOAT128 | _Float128 | |
| 101 | + +----------------+--------------------+ |
| 102 | + |
| 103 | + If the companion processor defines '__STDC_IEC_60559_BFP__' and |
| 104 | + '__STDC_IEC_60559_TYPES__', then the constants 'C_FLOAT32' and |
| 105 | + 'C_FLOAT64' should have the same values as 'C_FLOAT' and |
| 106 | + 'C_DOUBLE', respectively (C2023 H.2.4.2). |
| 107 | + |
| 108 | +sp05. To the ISO_C_BINDING module, add the following integer named |
| 109 | + constants for real KIND parameters: |
| 110 | + |
| 111 | + +--------------------+--------------------+ |
| 112 | + | Named constant | C interchange type | |
| 113 | + +--------------------+--------------------+ |
| 114 | + | C_FLOAT16_COMPLEX | _Float16_Complex | |
| 115 | + | C_FLOAT32_COMPLEX | _Float32_Complex | |
| 116 | + | C_FLOAT64_COMPLEX | _Float64_Complex | |
| 117 | + | C_FLOAT128_COMPLEX | _Float128_Complex | |
| 118 | + +--------------------+--------------------+ |
| 119 | + |
| 120 | + The values of each of these named constants shall be the same as |
| 121 | + the respective constants defined in sp01. |
| 122 | + |
| 123 | +sp07. To the ISO_C_BINDING module, add the following integer named |
| 124 | + constants for real KIND parameters: |
| 125 | + |
| 126 | + +----------------+-----------------+ |
| 127 | + | Named constant | C extended type | |
| 128 | + +----------------+-----------------+ |
| 129 | + | C_FLOAT32X | _Float32x | |
| 130 | + | C_FLOAT64X | _Float64x | |
| 131 | + | C_FLOAT128X | _Float128x | |
| 132 | + +----------------+-----------------+ |
| 133 | + |
| 134 | +sp09. To the ISO_C_BINDING module, add the following integer named |
| 135 | + constants for real KIND parameters: |
| 136 | + |
| 137 | + +---------------------+--------------------+ |
| 138 | + | Named constant | C extended type | |
| 139 | + +---------------------+--------------------+ |
| 140 | + | C_FLOAT32X_COMPLEX | _Float32x_Complex | |
| 141 | + | C_FLOAT64X_COMPLEX | _Float64x_Complex | |
| 142 | + | C_FLOAT128X_COMPLEX | _Float128x_Complex | |
| 143 | + +---------------------+--------------------+ |
| 144 | + |
| 145 | +sp11. To the ISO_C_BINDING module, add the following integer named |
| 146 | + constants for real KIND parameters: |
| 147 | + |
| 148 | + +----------------+--------------------+ |
| 149 | + | Named constant | C interchange type | |
| 150 | + +----------------+--------------------+ |
| 151 | + | C_DECIMAL32 | _Decimal32 | |
| 152 | + | C_DECIMAL64 | _Decimal64 | |
| 153 | + | C_DECIMAL128 | _Decimal128 | |
| 154 | + +----------------+--------------------+ |
| 155 | + |
| 156 | +=== END === |
0 commit comments