Skip to content

Commit 98cec13

Browse files
committed
Document how out-of-range inputs are handled
This changed recently so that overflow and underflow consistently return signed infinity or zero instead of nil. (Previously, overflow returned nil, underflow returned zero.) Among other benefits: * The new behavior distinguishes malformed input (nil) from valid but out-of-range input. * The new behavior preserves the sign of the input * The new behavior is consistent with how floating-point parsing behaves in other langauges Resolves rdar://76728925
1 parent 9b82fec commit 98cec13

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ extension ${Self}: LosslessStringConvertible {
128128
/// ${Self}("0x1.25e4") // Incorrect exponent format
129129
///
130130
/// - 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
132-
/// is `nil`.
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.
133135
@inlinable
134136
public init?<S: StringProtocol>(_ text: S) {
135137
%if bits == 16:

0 commit comments

Comments
 (0)