Skip to content

Make FloatingPoint require that Self.Magnitude == Self #17323

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
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions stdlib/public/Platform/tgmath.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import SwiftShims

// Generic functions implementable directly on FloatingPoint.
@_transparent
public func fabs<T: FloatingPoint>(_ x: T) -> T
where T.Magnitude == T {
@available(swift, deprecated: 4.2, renamed: "abs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why deprecate this specifically?

Copy link
Contributor Author

@stephentyrone stephentyrone Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reason that we deprecated other tgmath overlays whose functionality duplicates APIs available on [Binary]FloatingPoint and which don't offer compelling ergonomic advantages like sqrt or fma. We don't need to carry two names for the same function into the future, and abs is the better name for this. fabs is a curious artifact of the fact that C doesn't have overloaded functions.

public func fabs<T: FloatingPoint>(_ x: T) -> T {
return x.magnitude
}

Expand Down
15 changes: 2 additions & 13 deletions stdlib/public/core/FloatingPoint.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@ word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
/// print("Average: \(average)°F in \(validTemps.count) " +
/// "out of \(tempsFahrenheit.count) observations.")
/// // Prints "Average: 74.84°F in 5 out of 7 observations."
public protocol FloatingPoint: SignedNumeric, Strideable, Hashable {

// For the minimumMagnitude and maximumMagnitude methods
/// A type that can represent the absolute value of any possible value of the
/// conforming type.
associatedtype Magnitude = Self
public protocol FloatingPoint : SignedNumeric, Strideable, Hashable
where Magnitude == Self {

/// A type that can represent any written exponent.
associatedtype Exponent: SignedInteger
Expand Down Expand Up @@ -2505,13 +2501,6 @@ where Self.RawSignificand : FixedWidthInteger,

% end

/// Returns the absolute value of `x`.
@inlinable // FIXME(sil-serialize-all)
@_transparent
public func abs<T : FloatingPoint>(_ x: T) -> T where T.Magnitude == T {
return x.magnitude
}

extension FloatingPoint {
@inlinable // FIXME(sil-serialize-all)
@available(swift, obsoleted: 4, message: "Please use operators instead.")
Expand Down
12 changes: 0 additions & 12 deletions test/SourceKit/CodeComplete/complete_moduleimportdepth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ func test() {
// CHECK: key.modulename: "Swift"
// CHECK-NEXT: },

// CHECK-LABEL: key.name: "abs(:)",
// CHECK-NEXT: key.sourcetext: "abs(<#T##x: FloatingPoint##FloatingPoint#>)",
// CHECK-NEXT: key.description: "abs(x: FloatingPoint)",
// CHECK-NEXT: key.typename: "FloatingPoint",
// CHECK-NEXT: key.doc.brief: "Returns the absolute value of x.",
// CHECK-NEXT: key.context: source.codecompletion.context.othermodule,
// CHECK-NEXT: key.moduleimportdepth: 1,
// CHECK-NEXT: key.num_bytes_to_erase: 0,
// CHECK-NOT: key.modulename
// CHECK: key.modulename: "Swift"
// CHECK-NEXT: },

// FooHelper.FooHelperExplicit == 1
// CHECK-LABEL: key.name: "fooHelperExplicitFrameworkFunc1(:)",
// CHECK-NEXT: key.sourcetext: "fooHelperExplicitFrameworkFunc1(<#T##a: Int32##Int32#>)",
Expand Down