@@ -53,13 +53,14 @@ extension ${Self}: LosslessStringConvertible {
53
53
/// Creates a new instance from the given string.
54
54
///
55
55
/// The string passed as `text` can represent a real number in decimal or
56
- /// hexadecimal format or special floating-point values for infinity and NaN
57
- /// ("not a number").
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,
58
+ /// the optional initializer will fail and return `nil`.
58
59
///
59
60
/// The `text` string may begin with a plus or minus sign character (`+` or
60
61
/// `-`) followed by one of the following formats:
61
62
///
62
- /// - A *decimal value * contains a significand consisting of one
63
+ /// - A *decimal string * contains a significand consisting of one
63
64
/// or more decimal digits that may include a decimal point:
64
65
///
65
66
/// let c = ${Self}("-1.0")
@@ -68,19 +69,19 @@ extension ${Self}: LosslessStringConvertible {
68
69
/// let d = ${Self}("28.375")
69
70
/// // d == 28.375
70
71
///
71
- /// A decimal value may also include an exponent following the significand,
72
- /// indicating the power of 10 by which the significand should be
73
- /// multiplied. If included, the exponent is separated by a single
72
+ /// A decimal string may also include an exponent following the
73
+ /// significand, indicating the power of 10 by which the significand should
74
+ /// be multiplied. If included, the exponent is separated by a single
74
75
/// character, `e` or `E`, and consists of an optional plus or minus sign
75
76
/// character and a sequence of decimal digits.
76
77
///
77
78
/// let e = ${Self}("2837.5e-2")
78
79
/// // e == 28.375
79
80
///
80
81
/// A decimal string is converted into a correctly-rounded ${Self}
81
- /// value using IEEE 754 round-to-nearest
82
- /// conventions. Very small values are converted to positive or
83
- /// negative zero, very large values are converted
82
+ /// instance using IEEE 754 round-to-nearest
83
+ /// conventions. Very small values are rounded to positive or
84
+ /// negative zero, very large values are rounded
84
85
/// to plus or minus infinity.
85
86
///
86
87
/// let y = ${Self}("1.23e-9999")
@@ -97,14 +98,14 @@ extension ${Self}: LosslessStringConvertible {
97
98
/// let s = ${Self}("-7.89e7206")
98
99
/// // s == ${Self}.-infinity
99
100
///
100
- /// - A *hexadecimal value * contains a significand consisting of
101
- // `0X` or `0x` followed by one or more hexadecimal digits that may
101
+ /// - A *hexadecimal string * contains a significand consisting of
102
+ /// `0X` or `0x` followed by one or more hexadecimal digits that may
102
103
/// include a decimal point.
103
104
///
104
105
/// let f = ${Self}("0x1c.6")
105
106
/// // f == 28.375
106
107
///
107
- /// A hexadecimal value may also include an exponent
108
+ /// A hexadecimal string may also include an exponent
108
109
/// indicating the power of 2 by which the significand should
109
110
/// be multiplied. If included, the exponent is separated by a single
110
111
/// character, `p` or `P`, and consists of an optional plus or minus sign
@@ -113,9 +114,9 @@ extension ${Self}: LosslessStringConvertible {
113
114
/// let g = ${Self}("0x1.c6p4")
114
115
/// // g == 28.375
115
116
///
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
117
+ /// As with decimal strings, hexadecimal strings are rounded
118
+ /// to the closest ${Self} instance to the real number. Very small
119
+ /// or very large values are rounded to plus or minus zero or plus
119
120
/// or minus infinity.
120
121
///
121
122
/// - The input strings `"inf"` or `"infinity"` (case insensitive)
@@ -134,7 +135,7 @@ extension ${Self}: LosslessStringConvertible {
134
135
/// // n?.isNaN == true
135
136
/// // n?.sign == .minus
136
137
///
137
- /// A NaN value may also include a payload in parentheses following the
138
+ /// A NaN string may also include a payload in parentheses following the
138
139
/// `"nan"` keyword. The payload consists of a sequence of decimal digits,
139
140
/// or the characters `0X` or `0x` followed by a sequence of hexadecimal
140
141
/// digits. If the payload contains any other characters, it is ignored.
@@ -145,16 +146,15 @@ extension ${Self}: LosslessStringConvertible {
145
146
/// // p?.isNaN == true
146
147
/// // String(p!) == "nan(0x10)"
147
148
///
148
- /// - A value in any other format or containing additional characters
149
+ /// - A string in any other format or containing additional characters
149
150
/// results in a `nil` value. For example, the following conversions
150
151
/// result in `nil`:
151
152
///
152
153
/// ${Self}(" 5.0") // Includes whitespace
153
154
/// ${Self}("±2.0") // Invalid character
154
155
/// ${Self}("0x1.25e4") // Incorrect exponent format
155
156
///
156
- /// - Parameter text: The input string to convert to a `${Self}?` instance.
157
- /// The value will be `nil` if the input is incorrectly formatted.
157
+ /// - Parameter text: An input string to convert to a `${Self}?` instance.
158
158
@inlinable
159
159
public init?<S: StringProtocol>(_ text: S) {
160
160
%if bits == 16:
0 commit comments