@@ -155,15 +155,44 @@ UnaryFunctions = [
155
155
'acos', 'asin', 'atan', 'tan',
156
156
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
157
157
'expm1 ',
158
- 'log1 p',
159
- 'erf', 'erfc',
158
+ 'log1 p', 'logb' ,
159
+ 'cbrt' , ' erf', 'erfc' , 'tgamma ',
160
160
]
161
161
162
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
163
165
UnaryIntrinsicFunctions = [
164
- 'cos', 'sin', 'exp', 'exp2 ', 'log', 'log10 ', 'log2 ', 'nearbyint', 'rint'
166
+ 'cos', 'sin',
167
+ 'exp', 'exp2 ',
168
+ 'log', 'log10 ', 'log2 ',
169
+ 'nearbyint', 'rint',
165
170
]
166
171
172
+ # ( T, T) - > T
173
+ BinaryFunctions = [
174
+ 'atan2 ', 'hypot', 'pow',
175
+ 'copysign', 'nextafter', 'fdim', 'fmax', 'fmin'
176
+ ]
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
+
167
196
def AllFloatTypes( ) :
168
197
for bits in allFloatBits:
169
198
yield floatName ( bits) , cFloatName( bits) , cFuncSuffix( bits)
@@ -197,117 +226,60 @@ def TypedBinaryFunctions():
197
226
% end
198
227
@_transparent
199
228
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
200
- return ${ T} . ${ ufunc} ( x )
229
+ return ${ T} ( ${ ufunc} $ { f } ( $ { CT } ( x ) ) )
201
230
}
202
231
% if T == 'Float80 ':
203
232
#endif
204
233
% end
205
234
206
235
% end
207
- @_transparent
208
- public func cbrt( _ x: Float ) -> Float {
209
- return Float . root ( x, 3 )
210
- }
211
-
212
- @available ( swift, deprecated: 5.1 , message: " Use `x.exponent` or `floor(log2(x))`. " )
213
- @_transparent
214
- public func logb( _ x: Float ) -> Float {
215
- return Float . log2 ( x) . rounded ( . down)
216
- }
217
-
218
- @_transparent
219
- public func tgamma( _ x: Float ) -> Float {
220
- return Float . gamma ( x)
221
- }
222
-
223
- #if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
224
- @_transparent
225
- public func cbrt( _ x: Float80 ) -> Float80 {
226
- return Float80 . root ( x, 3 )
227
- }
228
-
229
- @available ( swift, deprecated: 5.1 , message: " Use `x.exponent` or `floor(log2(x))`. " )
230
- @_transparent
231
- public func logb( _ x: Float80 ) -> Float80 {
232
- return Float80 . log2 ( x) . rounded ( . down)
233
- }
234
-
235
- @_transparent
236
- public func tgamma( _ x: Float80 ) -> Float80 {
237
- return Float80 . gamma ( x)
238
- }
239
- #endif
240
236
237
+ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
241
238
// Unary intrinsic functions
242
239
// Note these have a corresponding LLVM intrinsic
243
240
% for T, ufunc in TypedUnaryIntrinsicFunctions( ) :
244
241
% if T == 'Float80 ':
245
242
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
246
243
% end
247
- % if ufunc [ - 3 : ] != 'int':
248
244
@_transparent
249
245
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
250
- return $ { T } . ${ ufunc} ( x)
246
+ return _ ${ ufunc} ( x)
251
247
}
252
- % else :
253
- @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
254
263
@_transparent
255
264
public func ${ ufunc} ( _ x: ${ T} ) - > ${ T} {
256
- return x . rounded ( . toNearestOrEven )
265
+ return $ { T } ( $ { ufunc } $ { f } ( $ { CT } ( x ) ) )
257
266
}
258
- % end
259
- % if T == 'Float80 ':
267
+ % if T == 'Float80 ':
260
268
#endif
269
+ % end
261
270
% end
262
-
263
271
% end
272
+ #endif
264
273
265
274
// Binary functions
266
- % for T, CT, f in OverlayFloatTypes ( ) :
275
+
276
+ % for T, CT, f, bfunc in TypedBinaryFunctions( ) :
267
277
% if T == 'Float80 ':
268
278
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
269
279
% end
270
280
@_transparent
271
- public func atan2( _ y: ${ T} , _ x: ${ T} ) -> ${ T} {
272
- return ${ T} . atan2 ( y: y, x: x)
273
- }
274
-
275
- @_transparent
276
- public func hypot( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
277
- return ${ T} . hypot( x , y )
278
- }
279
-
280
- @_transparent
281
- public func pow( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
282
- return ${ T} . pow( x , y )
283
- }
284
-
285
- @_transparent
286
- public func copysign( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
287
- return ${ T} ( signOf: y , magnitudeOf: x )
288
- }
289
-
290
- @_transparent
291
- public func fdim( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
292
- return ${ T} ( fdim${ f} ( ${ CT} ( x ) , ${ CT} ( y ) ) )
293
- }
294
-
295
- @available ( swift, deprecated: 5.1 , message: " Use the .nextUp and .nextDown properties. " )
296
- @_transparent
297
- public func nextafter( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
298
- return y > x ? x. nextUp : ( y < x ? x. nextDown : y)
299
- }
300
-
301
- @available ( swift, deprecated: 5.1 , message: " Use ${T}.minimum( ) or Swift.min( ) " )
302
- @_transparent
303
- public func fmin( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
304
- return . minimum( x, y)
305
- }
306
-
307
- @available ( swift, deprecated: 5.1 , message: " Use ${T}.maximum( ) or Swift.max( ) " )
308
- @_transparent
309
- public func fmax( _ x: ${ T} , _ y: ${ T} ) -> ${ T} {
310
- return . maximum( x, y)
281
+ public func ${ bfunc} ( _ lhs: ${ T} , _ rhs: ${ T} ) - > ${ T} {
282
+ return ${ T} ( ${ bfunc} ${ f} ( ${ CT} ( lhs) , ${ CT} ( rhs) ) )
311
283
}
312
284
% if T == 'Float80 ':
313
285
#endif
@@ -325,7 +297,9 @@ public func fmax(_ x: ${T}, _ y: ${T}) -> ${T} {
325
297
% end
326
298
@_transparent
327
299
public func lgamma( _ x: ${ T} ) - > ( ${ T} , Int) {
328
- 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) )
329
303
}
330
304
#endif
331
305
0 commit comments