Skip to content

Commit 47f13ec

Browse files
xwustephentyrone
authored andcommitted
[stdlib] Align behavior of generic NaN conversion to that of concrete types (#17746)
1 parent 00843da commit 47f13ec

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,9 @@ extension BinaryFloatingPoint {
21852185
sign: source.sign,
21862186
exponentBitPattern: Self.nan.exponentBitPattern,
21872187
significandBitPattern: payload | Self.nan.significandBitPattern)
2188-
return payload_ == payload ? (value, true) : (value, false)
2188+
// We define exactness by equality after roundtripping; since NaN is never
2189+
// equal to itself, it can never be converted exactly.
2190+
return (value, false)
21892191
}
21902192

21912193
let exponent = source.exponent
@@ -2299,8 +2301,7 @@ extension BinaryFloatingPoint {
22992301
/// exactly.
23002302
///
23012303
/// If the given floating-point value cannot be represented exactly, the
2302-
/// result is `nil`. A value that is NaN ("not a number") cannot be
2303-
/// represented exactly if its payload cannot be encoded exactly.
2304+
/// result is `nil`.
23042305
///
23052306
/// - Parameter value: A floating-point value to be converted.
23062307
@inlinable // FIXME(sil-serialize-all)

0 commit comments

Comments
 (0)