Skip to content

Fixes example snippets in FloatingPoint.swift #31729

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
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
10 changes: 7 additions & 3 deletions stdlib/public/core/FloatingPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@
///
/// let temperatureData = ["21.5", "19.25", "27", "no data", "28.25", "no data", "23"]
/// let tempsCelsius = temperatureData.map { Double($0) ?? .nan }
/// // tempsCelsius == [21.5, 19.25, 27, nan, 28.25, nan, 23.0]
/// print(tempsCelsius)
/// // Prints "[21.5, 19.25, 27, nan, 28.25, nan, 23.0]"
///
///
/// Note that some elements in the `temperatureData ` array are not valid
/// numbers. When these invalid strings are parsed by the `Double` failable
Expand All @@ -135,7 +137,8 @@
/// Next, the observations in Celsius are converted to Fahrenheit:
///
/// let tempsFahrenheit = tempsCelsius.map { $0 * 1.8 + 32 }
/// // tempsFahrenheit == [70.7, 66.65, 80.6, nan, 82.85, nan, 73.4]
/// print(tempsFahrenheit)
/// // Prints "[70.7, 66.65, 80.6, nan, 82.85, nan, 73.4]"
///
/// The NaN values in the `tempsCelsius` array are propagated through the
/// conversion and remain NaN in `tempsFahrenheit`.
Expand Down Expand Up @@ -1104,7 +1107,8 @@ public protocol FloatingPoint: SignedNumeric, Strideable, Hashable
///
/// var numbers = [2.5, 21.25, 3.0, .nan, -9.5]
/// numbers.sort { !$1.isTotallyOrdered(belowOrEqualTo: $0) }
/// // numbers == [-9.5, 2.5, 3.0, 21.25, NaN]
/// print(numbers)
/// // Prints "[-9.5, 2.5, 3.0, 21.25, nan]"
///
/// The `isTotallyOrdered(belowOrEqualTo:)` method implements the total order
/// relation as defined by the [IEEE 754 specification][spec].
Expand Down