Skip to content

Commit 33226b0

Browse files
committed
Distinguish "string" (input), "value" or "number" (abstract real number that the string represents), and "instance" (the resulting ${Self}).
1 parent b183c7d commit 33226b0

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ extension ${Self}: LosslessStringConvertible {
5353
/// Creates a new instance from the given string.
5454
///
5555
/// 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`.
5859
///
5960
/// The `text` string may begin with a plus or minus sign character (`+` or
6061
/// `-`) followed by one of the following formats:
6162
///
62-
/// - A *decimal value* contains a significand consisting of one
63+
/// - A *decimal string* contains a significand consisting of one
6364
/// or more decimal digits that may include a decimal point:
6465
///
6566
/// let c = ${Self}("-1.0")
@@ -68,19 +69,19 @@ extension ${Self}: LosslessStringConvertible {
6869
/// let d = ${Self}("28.375")
6970
/// // d == 28.375
7071
///
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
7475
/// character, `e` or `E`, and consists of an optional plus or minus sign
7576
/// character and a sequence of decimal digits.
7677
///
7778
/// let e = ${Self}("2837.5e-2")
7879
/// // e == 28.375
7980
///
8081
/// 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
8485
/// to plus or minus infinity.
8586
///
8687
/// let y = ${Self}("1.23e-9999")
@@ -97,14 +98,14 @@ extension ${Self}: LosslessStringConvertible {
9798
/// let s = ${Self}("-7.89e7206")
9899
/// // s == ${Self}.-infinity
99100
///
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
102103
/// include a decimal point.
103104
///
104105
/// let f = ${Self}("0x1c.6")
105106
/// // f == 28.375
106107
///
107-
/// A hexadecimal value may also include an exponent
108+
/// A hexadecimal string may also include an exponent
108109
/// indicating the power of 2 by which the significand should
109110
/// be multiplied. If included, the exponent is separated by a single
110111
/// character, `p` or `P`, and consists of an optional plus or minus sign
@@ -113,9 +114,9 @@ extension ${Self}: LosslessStringConvertible {
113114
/// let g = ${Self}("0x1.c6p4")
114115
/// // g == 28.375
115116
///
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
119120
/// or minus infinity.
120121
///
121122
/// - The input strings `"inf"` or `"infinity"` (case insensitive)
@@ -134,7 +135,7 @@ extension ${Self}: LosslessStringConvertible {
134135
/// // n?.isNaN == true
135136
/// // n?.sign == .minus
136137
///
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
138139
/// `"nan"` keyword. The payload consists of a sequence of decimal digits,
139140
/// or the characters `0X` or `0x` followed by a sequence of hexadecimal
140141
/// digits. If the payload contains any other characters, it is ignored.
@@ -145,16 +146,15 @@ extension ${Self}: LosslessStringConvertible {
145146
/// // p?.isNaN == true
146147
/// // String(p!) == "nan(0x10)"
147148
///
148-
/// - A value in any other format or containing additional characters
149+
/// - A string in any other format or containing additional characters
149150
/// results in a `nil` value. For example, the following conversions
150151
/// result in `nil`:
151152
///
152153
/// ${Self}(" 5.0") // Includes whitespace
153154
/// ${Self}("±2.0") // Invalid character
154155
/// ${Self}("0x1.25e4") // Incorrect exponent format
155156
///
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.
158158
@inlinable
159159
public init?<S: StringProtocol>(_ text: S) {
160160
%if bits == 16:

0 commit comments

Comments
 (0)