2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -14,12 +14,11 @@ import SwiftShims
14
14
15
15
// Generic functions implementable directly on FloatingPoint.
16
16
@_transparent
17
- @available ( swift, deprecated: 4.2 , obsoleted : 5.1 , renamed: " Swift. abs" )
17
+ @available ( swift, deprecated: 4.2 , renamed: " abs " )
18
18
public func fabs< T: FloatingPoint > ( _ x: T ) -> T {
19
19
return x. magnitude
20
20
}
21
21
22
- @available ( swift, obsoleted: 5.1 , message: " Use Swift.sqrt(x) or x.squareRoot(). " )
23
22
@_transparent
24
23
public func sqrt< T: FloatingPoint > ( _ x: T ) -> T {
25
24
return x. squareRoot ( )
@@ -113,7 +112,7 @@ public func isnan<T: FloatingPoint>(_ value: T) -> Bool { fatalError() }
113
112
@available ( * , unavailable, message: " use the sign property. " )
114
113
public func signbit< T: FloatingPoint > ( _ value: T ) -> Int { fatalError ( ) }
115
114
116
- @available ( swift, deprecated: 4.2 , obsoleted : 5.1 , message: " use the exponent property. " )
115
+ @available ( swift, deprecated: 4.2 , message: " use the exponent property. " )
117
116
public func ilogb< T: BinaryFloatingPoint > ( _ x: T ) -> Int {
118
117
return Int ( x. exponent)
119
118
}
@@ -156,20 +155,44 @@ UnaryFunctions = [
156
155
'acos', 'asin', 'atan', 'tan',
157
156
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
158
157
'expm1 ',
159
- 'log1 p',
160
- 'erf', 'erfc',
158
+ 'log1 p', 'logb' ,
159
+ 'cbrt' , ' erf', 'erfc' , 'tgamma ',
161
160
]
162
161
163
162
# These functions have a corresponding LLVM intrinsic
163
+ # We call this intrinsic via the Builtin method so keep this list in
164
+ # sync with core/ BuiltinMath. swift. gyb
164
165
UnaryIntrinsicFunctions = [
165
- 'cos', 'sin', 'exp', 'exp2 ', 'log', 'log10 ', 'log2 ', 'nearbyint', 'rint'
166
+ 'cos', 'sin',
167
+ 'exp', 'exp2 ',
168
+ 'log', 'log10 ', 'log2 ',
169
+ 'nearbyint', 'rint',
166
170
]
167
171
168
172
# ( T, T) - > T
169
173
BinaryFunctions = [
170
- 'atan2 ', 'hypot', 'fdim', 'copysign'
174
+ 'atan2 ', 'hypot', 'pow',
175
+ 'copysign', 'nextafter', 'fdim', 'fmax', 'fmin'
171
176
]
172
177
178
+ # These functions have special implementations.
179
+ OtherFunctions = [
180
+ 'scalbn', 'lgamma', 'remquo', 'nan', 'jn', 'yn'
181
+ ]
182
+
183
+ # These functions are imported correctly as - is.
184
+ OkayFunctions = [ 'j0 ', 'j1 ', 'y0 ', 'y1 ']
185
+
186
+ # These functions are not supported for various reasons.
187
+ UnhandledFunctions = [
188
+ 'math_errhandling', 'scalbln',
189
+ 'lrint', 'lround', 'llrint', 'llround', 'nexttoward',
190
+ 'isgreater ', 'isgreaterequal ', 'isless ', 'islessequal ',
191
+ 'islessgreater', 'isunordered', '__exp10 ',
192
+ '__sincos', '__cospi', '__sinpi', '__tanpi', '__sincospi'
193
+ ]
194
+
195
+
173
196
def AllFloatTypes( ) :
174
197
for bits in allFloatBits:
175
198
yield floatName ( bits) , cFloatName( bits) , cFuncSuffix( bits)
@@ -203,74 +226,50 @@ def TypedBinaryFunctions():
203
226
% end
204
227
@_transparent
205
228
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
206
- return ${ T} . ${ ufunc} ( x )
229
+ return ${ T} ( ${ ufunc} $ { f } ( $ { CT } ( x ) ) )
207
230
}
208
231
% if T == 'Float80 ':
209
232
#endif
210
233
% end
211
234
212
235
% end
213
- @available ( swift, deprecated: 5.1 , message: " Use `root(x, 3)`. " )
214
- @_transparent
215
- public func cbrt( _ x: Float ) -> Float {
216
- return Float . root ( x, 3 )
217
- }
218
-
219
- @available ( swift, deprecated: 5.1 , message: " Use `x.exponent` or `floor(log2(x))`. " )
220
- @_transparent
221
- public func logb( _ x: Float ) -> Float {
222
- return Float . log2 ( x) . rounded ( . down)
223
- }
224
-
225
- @available ( swift, deprecated: 5.1 , message: " Use `gamma(x)`. " )
226
- @_transparent
227
- public func tgamma( _ x: Float ) -> Float {
228
- return Float . gamma ( x)
229
- }
230
-
231
- #if (arch(i386) || arch(x86_64)) && !os(Windows)
232
- @available ( swift, deprecated: 5.1 , message: " Use `root(x, 3)`. " )
233
- @_transparent
234
- public func cbrt( _ x: Float80 ) -> Float80 {
235
- return Float80 . root ( x, 3 )
236
- }
237
-
238
- @available ( swift, deprecated: 5.1 , message: " Use `x.exponent` or `floor(log2(x))`. " )
239
- @_transparent
240
- public func logb( _ x: Float80 ) -> Float80 {
241
- return Float80 . log2 ( x) . rounded ( . down)
242
- }
243
-
244
- @available ( swift, deprecated: 5.1 , message: " Use `gamma(x)`. " )
245
- @_transparent
246
- public func tgamma( _ x: Float80 ) -> Float80 {
247
- return Float80 . gamma ( x)
248
- }
249
- #endif
250
236
237
+ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
251
238
// Unary intrinsic functions
252
239
// Note these have a corresponding LLVM intrinsic
253
240
% for T, ufunc in TypedUnaryIntrinsicFunctions( ) :
254
241
% if T == 'Float80 ':
255
242
#if (arch(i386) || arch(x86_64)) && !os(Windows)
256
243
% end
257
- % if ufunc [ - 3 : ] != 'int':
258
244
@_transparent
259
245
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
260
- return $ { T } . ${ ufunc} ( x)
246
+ return _ ${ ufunc} ( x)
261
247
}
262
- % else :
263
- @available ( swift, deprecated: 5.1 , message: " Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven) instead. " )
248
+ % if T == 'Float80 ':
249
+ #endif
250
+ % end
251
+
252
+ % end
253
+ #else
254
+ // FIXME: As of now, we cannot declare 64-bit (Double/CDouble) overlays here.
255
+ // Since CoreFoundation also exports libc functions, they will conflict with
256
+ // Swift overlays when building Foundation. For now, just like normal
257
+ // UnaryFunctions, we define overlays only for OverlayFloatTypes.
258
+ % for ufunc in UnaryIntrinsicFunctions:
259
+ % for T, CT, f in OverlayFloatTypes( ) :
260
+ % if T == 'Float80 ':
261
+ #if (arch(i386) || arch(x86_64)) && !os(Windows)
262
+ % end
264
263
@_transparent
265
264
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
266
- return x . rounded ( . toNearestOrEven )
265
+ return $ { T } ( $ { ufunc } $ { f } ( $ { CT } ( x ) ) )
267
266
}
268
- % end
269
- % if T == 'Float80 ':
267
+ % if T == 'Float80 ':
270
268
#endif
269
+ % end
271
270
% end
272
-
273
271
% end
272
+ #endif
274
273
275
274
// Binary functions
276
275
@@ -288,54 +287,6 @@ public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} {
288
287
289
288
% end
290
289
291
- @_transparent
292
- public func pow( _ x: Float , _ y: Float ) -> Float {
293
- return Float . pow ( x, y)
294
- }
295
-
296
- @available ( swift, deprecated: 5.1 , message: " Use the .nextUp and .nextDown properties. " )
297
- @_transparent
298
- public func nextafter( _ x: Float , _ y: Float ) -> Float {
299
- return y > x ? x. nextUp : ( y < x ? x. nextDown : y)
300
- }
301
-
302
- @available ( swift, deprecated: 5.1 , message: " Use Float.minimum( ) or Swift.min( ) " )
303
- @_transparent
304
- public func fmin( _ x: Float , _ y: Float ) -> Float {
305
- return . minimum( x, y)
306
- }
307
-
308
- @available ( swift, deprecated: 5.1 , message: " Use Float.maximum( ) or Swift.max( ) " )
309
- @_transparent
310
- public func fmax( _ x: Float , _ y: Float ) -> Float {
311
- return . maximum( x, y)
312
- }
313
-
314
- #if (arch(i386) || arch(x86_64)) && !os(Windows)
315
- @_transparent
316
- public func pow( _ x: Float80 , _ y: Float80 ) -> Float80 {
317
- return Float80 . pow ( x, y)
318
- }
319
-
320
- @available ( swift, deprecated: 5.1 , message: " Use the .nextUp and .nextDown properties. " )
321
- @_transparent
322
- public func nextafter( _ x: Float80 , _ y: Float80 ) -> Float80 {
323
- return y > x ? x. nextUp : ( y < x ? x. nextDown : y)
324
- }
325
-
326
- @available ( swift, deprecated: 5.1 , message: " Use Float80.minimum( ) or Swift.min( ) " )
327
- @_transparent
328
- public func fmin( _ x: Float80 , _ y: Float80 ) -> Float80 {
329
- return Float80 . minimum ( x, y)
330
- }
331
-
332
- @available ( swift, deprecated: 5.1 , message: " Use Float80.maximum( ) or Swift.max( ) " )
333
- @_transparent
334
- public func fmax( _ x: Float80 , _ y: Float80 ) -> Float80 {
335
- return Float80 . maximum ( x, y)
336
- }
337
- #endif
338
-
339
290
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return .
340
291
% for T, CT, f in AllFloatTypes( ) :
341
292
% if T == 'Float80 ':
@@ -344,10 +295,11 @@ public func fmax(_ x: Float80, _ y: Float80) -> Float80 {
344
295
// lgamma not available on Windows, apparently?
345
296
#if !os(Windows)
346
297
% end
347
- @available ( swift, deprecated: 5.1 , message: " Use (logGamma(x), signGamma(x)). " )
348
298
@_transparent
349
299
public func lgamma( _ x: ${ T} ) - > ( ${ T} , Int) {
350
- return ( ${ T} . logGamma ( x) , ${ T} . signGamma ( x) == . plus ? 1 : - 1 )
300
+ var sign = Int32 ( 0 )
301
+ let value = lgamma ${ f} _r( ${ CT} ( x) , & sign)
302
+ return ( ${ T} ( value) , Int ( sign) )
351
303
}
352
304
#endif
353
305
@@ -374,8 +326,8 @@ public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) {
374
326
% if T == 'Float80 ':
375
327
#if (arch(i386) || arch(x86_64)) && !os(Windows)
376
328
% end
377
- @available ( swift, deprecated: 4.2 , obsoleted : 5.1 , message:
378
- " use ${T}(nan: ${T}.RawSignificand). " )
329
+ @available ( swift, deprecated: 4.2 , message:
330
+ " use ${T}(nan: ${T}.RawSignificand) instead . " )
379
331
@_transparent
380
332
public func nan( _ tag: String) - > ${ T} {
381
333
return ${ T} ( nan ${ f} ( tag) )
0 commit comments