Skip to content

Commit f0a6d6f

Browse files
authored
Merge pull request swiftlang#33803 from xwu/fp-init-specialization
[stdlib] Make use of protocol requirements to convert from concrete floating-point types
2 parents b9d1b98 + b604635 commit f0a6d6f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

stdlib/public/core/FloatingPoint.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,26 @@ extension BinaryFloatingPoint {
18901890
/// - Parameter value: A floating-point value to be converted.
18911891
@inlinable
18921892
public init<Source: BinaryFloatingPoint>(_ value: Source) {
1893-
self = Self._convert(from: value).value
1893+
#if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst))
1894+
if #available(iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
1895+
if case let value_ as Float16 = value {
1896+
self = Self(Float(value_))
1897+
return
1898+
}
1899+
}
1900+
#endif
1901+
switch value {
1902+
case let value_ as Float:
1903+
self = Self(value_)
1904+
case let value_ as Double:
1905+
self = Self(value_)
1906+
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
1907+
case let value_ as Float80:
1908+
self = Self(value_)
1909+
#endif
1910+
default:
1911+
self = Self._convert(from: value).value
1912+
}
18941913
}
18951914

18961915
/// Creates a new instance from the given value, if it can be represented

0 commit comments

Comments
 (0)