Skip to content

Commit 42f79b0

Browse files
committed
[stdlib] Make use of protocol requirements to convert from concrete types
1 parent b62328b commit 42f79b0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

stdlib/public/core/FloatingPoint.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,18 @@ 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+
switch value {
1894+
case let value_ as Float:
1895+
self = Self(value_)
1896+
case let value_ as Double:
1897+
self = Self(value_)
1898+
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
1899+
case let value_ as Float80:
1900+
self = Self(value_)
1901+
#endif
1902+
default:
1903+
self = Self._convert(from: value).value
1904+
}
18941905
}
18951906

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

0 commit comments

Comments
 (0)