Skip to content

Commit acc5fd5

Browse files
authored
Merge pull request #3898 from natecook1000/nc-revise-fp
[stdlib] Revise and expand floating-point documentation
2 parents e3d8448 + 29c9c61 commit acc5fd5

File tree

5 files changed

+1665
-398
lines changed

5 files changed

+1665
-398
lines changed

stdlib/public/core/Comparable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
/// - Note: A conforming type may contain a subset of values which are treated
132132
/// as exceptional---that is, values that are outside the domain of
133133
/// meaningful arguments for the purposes of the `Comparable` protocol. For
134-
/// example, the special not-a-number (`FloatingPoint.nan`) value for
135-
/// floating-point types compares as neither less than, greater than, nor
134+
/// example, the special "not a number" value for floating-point types
135+
/// (`FloatingPoint.nan`) compares as neither less than, greater than, nor
136136
/// equal to any normal floating-point value. Exceptional values need not
137137
/// take part in the strict total order.
138138
public protocol Comparable : Equatable {

stdlib/public/core/CompilerProtocols.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,32 @@ public protocol _ExpressibleByBuiltinFloatLiteral {
205205
init(_builtinFloatLiteral value: _MaxBuiltinFloatType)
206206
}
207207

208-
/// Conforming types can be initialized with floating point literals.
208+
/// A type that can be initialized with a floating-point literal.
209+
///
210+
/// The standard library floating-point types---`Float`, `Double`, and
211+
/// `Float80` where available---all conform to the `ExpressibleByFloatLiteral`
212+
/// protocol. You can initialize a variable or constant of any of these types
213+
/// by assigning a floating-point literal.
214+
///
215+
/// // Type inferred as 'Double'
216+
/// let threshold = 6.0
217+
///
218+
/// // An array of 'Double'
219+
/// let measurements = [2.2, 4.1, 3.65, 4.2, 9.1]
220+
///
221+
/// Conforming to ExpressibleByFloatLiteral
222+
/// =======================================
223+
///
224+
/// To add `ExpressibleByFloatLiteral` conformance to your custom type,
225+
/// implement the required initializer.
209226
public protocol ExpressibleByFloatLiteral {
227+
/// A type that can represent a floating-point literal.
228+
///
229+
/// Valid types for `FloatLiteralType` are `Float`, `Double`, and `Float80`
230+
/// where available.
210231
associatedtype FloatLiteralType : _ExpressibleByBuiltinFloatLiteral
211-
/// Create an instance initialized to `value`.
232+
233+
/// Creates an instance initialized to the specified floating-point value.
212234
init(floatLiteral value: FloatLiteralType)
213235
}
214236

0 commit comments

Comments
 (0)