@@ -56,12 +56,11 @@ extension ${Self}: LosslessStringConvertible {
56
56
/// hexadecimal format or special floating-point values for infinity and NaN
57
57
/// ("not a number").
58
58
///
59
- /// The given string may begin with a plus or minus sign character (`+` or
60
- /// `-`). The allowed formats for each of these representations is then as
61
- /// follows:
59
+ /// The `text` string may begin with a plus or minus sign character (`+` or
60
+ /// `-`) followed by one of the following formats:
62
61
///
63
- /// - A *decimal value* contains the significand, a sequence of decimal
64
- /// digits that may include a decimal point.
62
+ /// - A *decimal value* contains a significand consisting of one
63
+ /// or more decimal digits that may include a decimal point:
65
64
///
66
65
/// let c = ${Self}("-1.0")
67
66
/// // c == -1.0
@@ -78,32 +77,58 @@ extension ${Self}: LosslessStringConvertible {
78
77
/// let e = ${Self}("2837.5e-2")
79
78
/// // e == 28.375
80
79
///
81
- /// - A *hexadecimal value* contains the significand, either `0X` or `0x`,
82
- /// followed by a sequence of hexadecimal digits. The significand may
80
+ /// A decimal string is converted into a correctly-rounded ${Self}
81
+ /// value using IEEE 754 round-to-nearest
82
+ /// conventions. Very small values will be converted to positive or
83
+ /// negative zero, very large values will be converted
84
+ /// to plus or minus infinity.
85
+ ///
86
+ /// let y = ${Self}("1.23e-9999")
87
+ /// // y == 0.0
88
+ /// // y?.sign == .plus
89
+ ///
90
+ /// let z = ${Self}("-7.89e-7206")
91
+ /// // z == -0.0
92
+ /// // z?.sign == .minus
93
+ ///
94
+ /// let r = ${Self}("1.23e17802")
95
+ /// // r == ${Self}.infinity
96
+ ///
97
+ /// let s = ${Self}("-7.89e7206")
98
+ /// // s == ${Self}.-infinity
99
+ ///
100
+ /// - A *hexadecimal value* contains a significand consisting of
101
+ // `0X` or `0x` followed by one or more hexadecimal digits that may
83
102
/// include a decimal point.
84
103
///
85
104
/// let f = ${Self}("0x1c.6")
86
105
/// // f == 28.375
87
106
///
88
- /// A hexadecimal value may also include an exponent following the
89
- /// significand, indicating the power of 2 by which the significand should
107
+ /// A hexadecimal value may also include an exponent
108
+ /// indicating the power of 2 by which the significand should
90
109
/// be multiplied. If included, the exponent is separated by a single
91
110
/// character, `p` or `P`, and consists of an optional plus or minus sign
92
111
/// character and a sequence of decimal digits.
93
112
///
94
113
/// let g = ${Self}("0x1.c6p4")
95
114
/// // g == 28.375
96
115
///
97
- /// - A value of *infinity* contains one of the strings `"inf"` or
98
- /// `"infinity"`, case insensitive.
116
+ /// As with decimal strings, hexadecimal strings are converted
117
+ /// to the closest ${Self} value to the real number. Very small
118
+ /// or very large values are converted to plus or minus zero or plus
119
+ /// or minus infinity.
120
+ ///
121
+ /// - The input strings `"inf"` or `"infinity"` (case insensitive)
122
+ /// are converted to an infinite result:
99
123
///
100
124
/// let i = ${Self}("inf")
101
125
/// // i == ${Self}.infinity
102
126
///
103
127
/// let j = ${Self}("-Infinity")
104
128
/// // j == -${Self}.infinity
105
129
///
106
- /// - A value of *NaN* contains the string `"nan"`, case insensitive.
130
+ /// - An input string of `"nan"` (case insensitive) is converted
131
+ /// into a *NaN* value:
107
132
///
108
133
/// let n = ${Self}("-nan")
109
134
/// // n?.isNaN == true
@@ -120,18 +145,16 @@ extension ${Self}: LosslessStringConvertible {
120
145
/// // p?.isNaN == true
121
146
/// // String(p!) == "nan(0x10)"
122
147
///
123
- /// Passing any other format or any additional characters as `text` results
124
- /// in `nil`. For example, the following conversions result in `nil`:
148
+ /// - A value in any other format or containing additional characters
149
+ /// results in a `nil` value. For example, the following conversions
150
+ /// result in `nil`:
125
151
///
126
- /// ${Self}(" 5.0") // Includes whitespace
127
- /// ${Self}("±2.0") // Invalid character
128
- /// ${Self}("0x1.25e4") // Incorrect exponent format
152
+ /// ${Self}(" 5.0") // Includes whitespace
153
+ /// ${Self}("±2.0") // Invalid character
154
+ /// ${Self}("0x1.25e4") // Incorrect exponent format
129
155
///
130
- /// - Parameter text: The input string to convert to a `${Self}` instance. If
131
- /// `text` has invalid characters or is in an invalid format, the result is
132
- /// `nil`. If the input is valid but the parsed value would be too small
133
- /// or large for the type, the result will be a zero or infinity with the
134
- /// appropriate sign.
156
+ /// - Parameter text: The input string to convert to a `${Self}?` instance.
157
+ /// The value will be `nil` if the input is incorrectly formatted.
135
158
@inlinable
136
159
public init?<S: StringProtocol>(_ text: S) {
137
160
%if bits == 16:
0 commit comments