Skip to content

[stdlib] Align behavior of generic NaN conversion to that of concrete types #17746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions stdlib/public/core/FloatingPoint.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,9 @@ extension BinaryFloatingPoint {
sign: source.sign,
exponentBitPattern: Self.nan.exponentBitPattern,
significandBitPattern: payload | Self.nan.significandBitPattern)
return payload_ == payload ? (value, true) : (value, false)
// We define exactness by equality after roundtripping; since NaN is never
// equal to itself, it can never be converted exactly.
return (value, false)
}

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