Skip to content

Commit 8708c7b

Browse files
committed
Remove Real[Functions] protocols pending re-review
Temporarily pull these back so we can make minor tweaks to the design and get a re-review on SE.
1 parent 4b4a04f commit 8708c7b

File tree

3 files changed

+2
-132
lines changed

3 files changed

+2
-132
lines changed

stdlib/public/Darwin/CoreGraphics/CGFloat.swift.gyb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public func %=(lhs: inout CGFloat, rhs: CGFloat) {
515515

516516
%from SwiftMathFunctions import *
517517

518-
extension CGFloat: Real {
518+
extension CGFloat: ElementaryFunctions {
519519
% for func in ElementaryFunctions + RealFunctions:
520520

521521
@_alwaysEmitIntoClient
@@ -558,8 +558,6 @@ extension CGFloat: Real {
558558
return CGFloat(NativeType.logGamma(x.native))
559559
}
560560

561-
// We get this for free from an extension defined on Real, but we need it
562-
// on the concrete type as well for back-deployment to older stdlib versions.
563561
@_alwaysEmitIntoClient
564562
public static func signGamma(_ x: CGFloat) -> FloatingPointSign {
565563
if x >= 0 { return .plus }

stdlib/public/core/MathFunctions.swift.gyb

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -60,82 +60,12 @@ public protocol ElementaryFunctions {
6060
static func root(_ x: Self, _ n: Int) -> Self
6161
}
6262

63-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
64-
public protocol RealFunctions: ElementaryFunctions {
65-
%for func in RealFunctions:
66-
67-
${func.comment}
68-
static func ${func.decl("Self")}
69-
%end
70-
71-
/// `atan(y/x)` with quadrant fixup.
72-
///
73-
/// There is an infinite family of angles whose tangent is `y/x`. `atan2`
74-
/// selects the representative that is the angle between the vector `(x, y)`
75-
/// and the real axis in the range [-π, π].
76-
static func atan2(y: Self, x: Self) -> Self
77-
78-
#if !os(Windows)
79-
// lgamma is not available on Windows.
80-
// TODO: provide an implementation of lgamma with the stdlib to support
81-
// Windows so we can vend a uniform interface.
82-
83-
/// `log(gamma(x))` computed without undue overflow.
84-
///
85-
/// `log(abs(gamma(x)))` is returned. To get the sign of `gamma(x)` cheaply,
86-
/// use `signGamma(x)`.
87-
static func logGamma(_ x: Self) -> Self
88-
#endif
89-
}
90-
91-
/// A type that models the real numbers.
92-
///
93-
/// Conformance to this protocol means that all the FloatingPoint operations
94-
/// are available, as well as the ElementaryFunctions, plus the following
95-
/// additional math functions: atan2, erf, erc, hypot, tgamma.
96-
///
97-
/// logGamma and signGamma are also available on non-Windows platforms.
98-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
99-
public protocol Real: RealFunctions, FloatingPoint { }
100-
101-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
102-
extension Real {
103-
#if !os(Windows)
104-
// lgamma is not available on Windows; no lgamma means signGamma
105-
// is basically useless, so don't bother exposing it.
106-
107-
/// The sign of `gamma(x)`.
108-
///
109-
/// This function is typically used in conjunction with `logGamma(x)`, which
110-
/// computes `log(abs(gamma(x)))`, to recover the sign information that is
111-
/// lost to the absolute value.
112-
///
113-
/// `gamma(x)` has a simple pole at each non-positive integer and an
114-
/// essential singularity at infinity; we arbitrarily choose to return
115-
/// `.plus` for the sign in those cases. For all other values, `signGamma(x)`
116-
/// is `.plus` if `x >= 0` or `trunc(x)` is odd, and `.minus` otherwise.
117-
@_alwaysEmitIntoClient
118-
public static func signGamma(_ x: Self) -> FloatingPointSign {
119-
if x >= 0 { return .plus }
120-
let trunc = x.rounded(.towardZero)
121-
// Treat poles as gamma(x) == +inf. This is arbitrary, but we need to
122-
// pick one sign or the other.
123-
if x == trunc { return .plus }
124-
// Result is .minus if trunc is even, .plus otherwise. To figure out if
125-
// trunc is even or odd, check if trunc/2 is an integer.
126-
let halfTrunc = trunc/2
127-
if halfTrunc == halfTrunc.rounded(.towardZero) { return .minus }
128-
return .plus
129-
}
130-
#endif
131-
}
132-
13363
%for type in all_floating_point_types():
13464
% if type.bits == 80:
13565
#if (arch(i386) || arch(x86_64)) && !os(Windows)
13666
% end
13767
% Self = type.stdlib_name
138-
extension ${Self}: Real {
68+
extension ${Self}: ElementaryFunctions {
13969
% for func in ElementaryFunctions + RealFunctions:
14070

14171
@_alwaysEmitIntoClient
@@ -179,9 +109,6 @@ extension ${Self}: Real {
179109
return _swift_stdlib_lgamma${type.cFuncSuffix}(x)
180110
}
181111

182-
// We get this for free from the extension above, but we also need it here
183-
// to facilitate back-deployment to standard library versions from before it
184-
// was introduced.
185112
@_alwaysEmitIntoClient
186113
public static func signGamma(_ x: ${Self}) -> FloatingPointSign {
187114
if x >= 0 { return .plus }
@@ -240,45 +167,7 @@ extension SIMD where Scalar: ElementaryFunctions {
240167
}
241168
}
242169

243-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
244-
extension SIMD where Scalar: RealFunctions {
245-
% for func in RealFunctions:
246-
247-
@_alwaysEmitIntoClient
248-
public static func ${func.decl("Self")} {
249-
var r = Self()
250-
for i in r.indices {
251-
r[i] = Scalar.${func.swiftName}(${func.params(suffix="[i]")})
252-
}
253-
return r
254-
}
255-
% end
256-
257-
@_alwaysEmitIntoClient
258-
public static func atan2(y: Self, x: Self) -> Self {
259-
var r = Self()
260-
for i in r.indices {
261-
r[i] = Scalar.atan2(y: y[i], x: x[i])
262-
}
263-
return r
264-
}
265-
266-
#if !os(Windows)
267-
@_alwaysEmitIntoClient
268-
public static func logGamma(_ x: Self) -> Self {
269-
var r = Self()
270-
for i in r.indices {
271-
r[i] = Scalar.logGamma(x[i])
272-
}
273-
return r
274-
}
275-
#endif
276-
}
277-
278170
%for n in [2,3,4,8,16,32,64]:
279171
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
280172
extension SIMD${n}: ElementaryFunctions where Scalar: ElementaryFunctions { }
281-
282-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
283-
extension SIMD${n}: RealFunctions where Scalar: RealFunctions { }
284173
%end

test/stdlib/MathFunctions.swift.gyb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ internal extension ElementaryFunctions where Self: BinaryFloatingPoint {
7979
}
8080
}
8181

82-
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
83-
internal extension Real where Self: BinaryFloatingPoint {
84-
static func realFunctionTests() {
85-
expectEqualWithTolerance(0.54041950027058415544357836460859991, Self.atan2(y: 0.375, x: 0.625))
86-
expectEqualWithTolerance(0.72886898685566255885926910969319788, Self.hypot(0.375, 0.625))
87-
expectEqualWithTolerance(0.4041169094348222983238250859191217675, Self.erf(0.375))
88-
expectEqualWithTolerance(0.5958830905651777016761749140808782324, Self.erfc(0.375))
89-
expectEqualWithTolerance(2.3704361844166009086464735041766525098, Self.gamma(0.375))
90-
#if !os(Windows)
91-
expectEqualWithTolerance( -0.11775527074107877445136203331798850, Self.logGamma(1.375), ulps: 16)
92-
expectEqual(.plus, Self.signGamma(1.375))
93-
expectEqual(.minus, Self.signGamma(-2.375))
94-
#endif
95-
}
96-
}
97-
9882
%for T in ['Float', 'Double', 'CGFloat', 'Float80']:
9983
% if T == 'Float80':
10084
#if (arch(i386) || arch(x86_64)) && !os(Windows)
@@ -106,7 +90,6 @@ internal extension Real where Self: BinaryFloatingPoint {
10690
MathTests.test("${T}") {
10791
if #available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) {
10892
${T}.elementaryFunctionTests()
109-
${T}.realFunctionTests()
11093
}
11194
}
11295

0 commit comments

Comments
 (0)