@@ -60,82 +60,12 @@ public protocol ElementaryFunctions {
60
60
static func root( _ x: Self , _ n: Int ) -> Self
61
61
}
62
62
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
-
133
63
% for type in all_floating_point_types( ) :
134
64
% if type. bits == 80 :
135
65
#if (arch(i386) || arch(x86_64)) && !os(Windows)
136
66
% end
137
67
% Self = type. stdlib_name
138
- extension ${ Self} : Real {
68
+ extension ${ Self} : ElementaryFunctions {
139
69
% for func in ElementaryFunctions + RealFunctions:
140
70
141
71
@_alwaysEmitIntoClient
@@ -179,9 +109,6 @@ extension ${Self}: Real {
179
109
return _swift_stdlib_lgamma ${ type. cFuncSuffix} ( x)
180
110
}
181
111
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.
185
112
@_alwaysEmitIntoClient
186
113
public static func signGamma( _ x: ${ Self} ) -> FloatingPointSign {
187
114
if x >= 0 { return . plus }
@@ -240,45 +167,7 @@ extension SIMD where Scalar: ElementaryFunctions {
240
167
}
241
168
}
242
169
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
-
278
170
% for n in [ 2 , 3 , 4 , 8 , 16 , 32 , 64 ] :
279
171
@available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * )
280
172
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 { }
284
173
% end
0 commit comments