@@ -54,12 +54,12 @@ extension ${Self}: LosslessStringConvertible {
54
54
///
55
55
/// The string passed as `text` can represent a real number in decimal or
56
56
/// hexadecimal format or can be in a special format representing infinity
57
- /// or NaN ("not a number"). If the `text` is not in a recognized format,
57
+ /// or NaN ("not a number"). If `text` is not in a recognized format,
58
58
/// the optional initializer will fail and return `nil`.
59
59
///
60
60
/// The `text` string consists of an optional
61
61
/// plus or minus sign character (`+` or `-`)
62
- /// followed by one of the following formats :
62
+ /// followed by one of the following:
63
63
///
64
64
/// - A *decimal string* contains a significand consisting of one
65
65
/// or more decimal digits that may include a decimal point:
@@ -79,27 +79,6 @@ extension ${Self}: LosslessStringConvertible {
79
79
/// let e = ${Self}("2837.5e-2")
80
80
/// // e == 28.375
81
81
///
82
- /// A decimal string is converted to a ${Self}
83
- /// instance using the IEEE 754 roundTiesToEven (default) rounding
84
- /// attribute.
85
- /// Very small values are rounded to positive or
86
- /// negative zero, very large values are rounded
87
- /// to plus or minus infinity.
88
- ///
89
- /// let y = ${Self}("1.23e-9999")
90
- /// // y == 0.0
91
- /// // y?.sign == .plus
92
- ///
93
- /// let z = ${Self}("-7.89e-7206")
94
- /// // z == -0.0
95
- /// // z?.sign == .minus
96
- ///
97
- /// let r = ${Self}("1.23e17802")
98
- /// // r == ${Self}.infinity
99
- ///
100
- /// let s = ${Self}("-7.89e7206")
101
- /// // s == ${Self}.-infinity
102
- ///
103
82
/// - A *hexadecimal string* contains a significand consisting of
104
83
/// `0X` or `0x` followed by one or more hexadecimal digits that may
105
84
/// include a decimal point.
@@ -116,11 +95,6 @@ extension ${Self}: LosslessStringConvertible {
116
95
/// let g = ${Self}("0x1.c6p4")
117
96
/// // g == 28.375
118
97
///
119
- /// As with decimal strings, hexadecimal strings are rounded
120
- /// to the closest ${Self} instance to the real number. Very small
121
- /// or very large values are rounded to plus or minus zero or plus
122
- /// or minus infinity.
123
- ///
124
98
/// - The input strings `"inf"` or `"infinity"` (case insensitive)
125
99
/// are converted to an infinite result:
126
100
///
@@ -148,21 +122,44 @@ extension ${Self}: LosslessStringConvertible {
148
122
/// // p?.isNaN == true
149
123
/// // String(p!) == "nan(0x10)"
150
124
///
151
- /// - A string in any other format or containing additional characters
152
- /// results in a `nil` value. For example, the following conversions
153
- /// result in `nil`:
125
+ /// A string in any other format than those described above
126
+ /// or containing additional characters
127
+ /// results in a `nil` value. For example, the following conversions
128
+ /// result in `nil`:
154
129
///
155
130
/// ${Self}(" 5.0") // Includes whitespace
156
131
/// ${Self}("±2.0") // Invalid character
157
132
/// ${Self}("0x1.25e4") // Incorrect exponent format
158
133
///
159
- /// - Parameter text: An input string to convert to a `${Self}?` instance.
134
+ /// A decimal or hexadecimal string is converted to a `${Self}`
135
+ /// instance using the IEEE 754 roundTiesToEven (default) rounding
136
+ /// attribute.
137
+ /// Values with absolute value smaller than `${Self}.leastNonzeroMagnitude`
138
+ /// are rounded to plus or minus zero.
139
+ /// Values with absolute value larger than `${Self}.greatestFiniteMagnitude`
140
+ /// are rounded to plus or minus infinity.
160
141
///
161
- /// Backwards compatibility note: Prior to Swift 5.4, a decimal or
142
+ /// let y = ${Self}("1.23e-9999")
143
+ /// // y == 0.0
144
+ /// // y?.sign == .plus
145
+ ///
146
+ /// let z = ${Self}("-7.89e-7206")
147
+ /// // z == -0.0
148
+ /// // z?.sign == .minus
149
+ ///
150
+ /// let r = ${Self}("1.23e17802")
151
+ /// // r == ${Self}.infinity
152
+ ///
153
+ /// let s = ${Self}("-7.89e7206")
154
+ /// // s == ${Self}.-infinity
155
+ ///
156
+ /// Note: Prior to Swift 5.4, a decimal or
162
157
/// hexadecimal input string whose value was too large to represent
163
- /// as a finite `${Self}` instance would return `nil` instead of
158
+ /// as a finite `${Self}` instance returned `nil` instead of
164
159
/// `${Self}.infinity`.
165
160
///
161
+ /// - Parameter text: An input string to convert to a `${Self}?` instance.
162
+ ///
166
163
@inlinable
167
164
public init?<S: StringProtocol>(_ text: S) {
168
165
%if bits == 16:
0 commit comments