Skip to content

Commit fbec09b

Browse files
committed
Consolidate format-independent discussion at the end
1 parent 2a47658 commit fbec09b

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ extension ${Self}: LosslessStringConvertible {
5454
///
5555
/// The string passed as `text` can represent a real number in decimal or
5656
/// 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,
5858
/// the optional initializer will fail and return `nil`.
5959
///
6060
/// The `text` string consists of an optional
6161
/// plus or minus sign character (`+` or `-`)
62-
/// followed by one of the following formats:
62+
/// followed by one of the following:
6363
///
6464
/// - A *decimal string* contains a significand consisting of one
6565
/// or more decimal digits that may include a decimal point:
@@ -79,27 +79,6 @@ extension ${Self}: LosslessStringConvertible {
7979
/// let e = ${Self}("2837.5e-2")
8080
/// // e == 28.375
8181
///
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-
///
10382
/// - A *hexadecimal string* contains a significand consisting of
10483
/// `0X` or `0x` followed by one or more hexadecimal digits that may
10584
/// include a decimal point.
@@ -116,11 +95,6 @@ extension ${Self}: LosslessStringConvertible {
11695
/// let g = ${Self}("0x1.c6p4")
11796
/// // g == 28.375
11897
///
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-
///
12498
/// - The input strings `"inf"` or `"infinity"` (case insensitive)
12599
/// are converted to an infinite result:
126100
///
@@ -148,21 +122,44 @@ extension ${Self}: LosslessStringConvertible {
148122
/// // p?.isNaN == true
149123
/// // String(p!) == "nan(0x10)"
150124
///
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`:
154129
///
155130
/// ${Self}(" 5.0") // Includes whitespace
156131
/// ${Self}("±2.0") // Invalid character
157132
/// ${Self}("0x1.25e4") // Incorrect exponent format
158133
///
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.
160141
///
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
162157
/// 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
164159
/// `${Self}.infinity`.
165160
///
161+
/// - Parameter text: An input string to convert to a `${Self}?` instance.
162+
///
166163
@inlinable
167164
public init?<S: StringProtocol>(_ text: S) {
168165
%if bits == 16:

0 commit comments

Comments
 (0)