|
11 | 11 |
|
12 | 12 | import _NumericsShims |
13 | 13 |
|
14 | | -// When building with a Swift 5.4 or later toolchain, Float16 is available on |
15 | | -// non-x86 macOS from 11.0 onward. |
16 | | -#if swift(>=5.4) && !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) |
| 14 | +// Float16 is only available on macOS when targeting arm64. |
| 15 | +#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) |
17 | 16 |
|
18 | 17 | @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
19 | 18 | extension Float16: Real { |
@@ -175,169 +174,4 @@ extension Float16: Real { |
175 | 174 | #endif |
176 | 175 | } |
177 | 176 |
|
178 | | -// When building with older Swift toolchains for macOS, Float16 is not |
179 | | -// available. We will drop support for these older toolchains at some |
180 | | -// future point and remove this duplication. |
181 | | -#elseif swift(>=5.3) && !(os(macOS) || targetEnvironment(macCatalyst)) |
182 | | - |
183 | | -@available(iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
184 | | -extension Float16: Real { |
185 | | - @_transparent |
186 | | - public static func cos(_ x: Float16) -> Float16 { |
187 | | - Float16(.cos(Float(x))) |
188 | | - } |
189 | | - |
190 | | - @_transparent |
191 | | - public static func sin(_ x: Float16) -> Float16 { |
192 | | - Float16(.sin(Float(x))) |
193 | | - } |
194 | | - |
195 | | - @_transparent |
196 | | - public static func tan(_ x: Float16) -> Float16 { |
197 | | - Float16(.tan(Float(x))) |
198 | | - } |
199 | | - |
200 | | - @_transparent |
201 | | - public static func acos(_ x: Float16) -> Float16 { |
202 | | - Float16(.acos(Float(x))) |
203 | | - } |
204 | | - |
205 | | - @_transparent |
206 | | - public static func asin(_ x: Float16) -> Float16 { |
207 | | - Float16(.asin(Float(x))) |
208 | | - } |
209 | | - |
210 | | - @_transparent |
211 | | - public static func atan(_ x: Float16) -> Float16 { |
212 | | - Float16(.atan(Float(x))) |
213 | | - } |
214 | | - |
215 | | - @_transparent |
216 | | - public static func cosh(_ x: Float16) -> Float16 { |
217 | | - Float16(.cosh(Float(x))) |
218 | | - } |
219 | | - |
220 | | - @_transparent |
221 | | - public static func sinh(_ x: Float16) -> Float16 { |
222 | | - Float16(.sinh(Float(x))) |
223 | | - } |
224 | | - |
225 | | - @_transparent |
226 | | - public static func tanh(_ x: Float16) -> Float16 { |
227 | | - Float16(.tanh(Float(x))) |
228 | | - } |
229 | | - |
230 | | - @_transparent |
231 | | - public static func acosh(_ x: Float16) -> Float16 { |
232 | | - Float16(.acosh(Float(x))) |
233 | | - } |
234 | | - |
235 | | - @_transparent |
236 | | - public static func asinh(_ x: Float16) -> Float16 { |
237 | | - Float16(.asinh(Float(x))) |
238 | | - } |
239 | | - |
240 | | - @_transparent |
241 | | - public static func atanh(_ x: Float16) -> Float16 { |
242 | | - Float16(.atanh(Float(x))) |
243 | | - } |
244 | | - |
245 | | - @_transparent |
246 | | - public static func exp(_ x: Float16) -> Float16 { |
247 | | - Float16(.exp(Float(x))) |
248 | | - } |
249 | | - |
250 | | - @_transparent |
251 | | - public static func expMinusOne(_ x: Float16) -> Float16 { |
252 | | - Float16(.expMinusOne(Float(x))) |
253 | | - } |
254 | | - |
255 | | - @_transparent |
256 | | - public static func log(_ x: Float16) -> Float16 { |
257 | | - Float16(.log(Float(x))) |
258 | | - } |
259 | | - |
260 | | - @_transparent |
261 | | - public static func log(onePlus x: Float16) -> Float16 { |
262 | | - Float16(.log(onePlus: Float(x))) |
263 | | - } |
264 | | - |
265 | | - @_transparent |
266 | | - public static func erf(_ x: Float16) -> Float16 { |
267 | | - Float16(.erf(Float(x))) |
268 | | - } |
269 | | - |
270 | | - @_transparent |
271 | | - public static func erfc(_ x: Float16) -> Float16 { |
272 | | - Float16(.erfc(Float(x))) |
273 | | - } |
274 | | - |
275 | | - @_transparent |
276 | | - public static func exp2(_ x: Float16) -> Float16 { |
277 | | - Float16(.exp2(Float(x))) |
278 | | - } |
279 | | - |
280 | | - @_transparent |
281 | | - public static func exp10(_ x: Float16) -> Float16 { |
282 | | - Float16(.exp10(Float(x))) |
283 | | - } |
284 | | - |
285 | | - @_transparent |
286 | | - public static func hypot(_ x: Float16, _ y: Float16) -> Float16 { |
287 | | - if x.isInfinite || y.isInfinite { return .infinity } |
288 | | - let xf = Float(x) |
289 | | - let yf = Float(y) |
290 | | - return Float16(.sqrt(xf*xf + yf*yf)) |
291 | | - } |
292 | | - |
293 | | - @_transparent |
294 | | - public static func gamma(_ x: Float16) -> Float16 { |
295 | | - Float16(.gamma(Float(x))) |
296 | | - } |
297 | | - |
298 | | - @_transparent |
299 | | - public static func log2(_ x: Float16) -> Float16 { |
300 | | - Float16(.log2(Float(x))) |
301 | | - } |
302 | | - |
303 | | - @_transparent |
304 | | - public static func log10(_ x: Float16) -> Float16 { |
305 | | - Float16(.log10(Float(x))) |
306 | | - } |
307 | | - |
308 | | - @_transparent |
309 | | - public static func pow(_ x: Float16, _ y: Float16) -> Float16 { |
310 | | - Float16(.pow(Float(x), Float(y))) |
311 | | - } |
312 | | - |
313 | | - @_transparent |
314 | | - public static func pow(_ x: Float16, _ n: Int) -> Float16 { |
315 | | - // Float16 is simpler than Float or Double, because the range of |
316 | | - // "interesting" exponents is pretty small; anything outside of |
317 | | - // -22707 ... 34061 simply overflows or underflows for every |
318 | | - // x that isn't zero or one. This whole range is representable |
319 | | - // as Float, so we can just use powf as long as we're a little |
320 | | - // bit (get it?) careful to preserve parity. |
321 | | - let clamped = min(max(n, -0x10000), 0x10000) | (n & 1) |
322 | | - return Float16(libm_powf(Float(x), Float(clamped))) |
323 | | - } |
324 | | - |
325 | | - @_transparent |
326 | | - public static func root(_ x: Float16, _ n: Int) -> Float16 { |
327 | | - Float16(.root(Float(x), n)) |
328 | | - } |
329 | | - |
330 | | - @_transparent |
331 | | - public static func atan2(y: Float16, x: Float16) -> Float16 { |
332 | | - Float16(.atan2(y: Float(y), x: Float(x))) |
333 | | - } |
334 | | - |
335 | | - #if !os(Windows) |
336 | | - @_transparent |
337 | | - public static func logGamma(_ x: Float16) -> Float16 { |
338 | | - Float16(.logGamma(Float(x))) |
339 | | - } |
340 | | - #endif |
341 | | -} |
342 | | - |
343 | 177 | #endif |
0 commit comments