Skip to content

Commit 7208f96

Browse files
committed
Make FloatingPoint require that Self.Magnitude == Self
We didn't have the where clause to express this constraint at the time that the FloatingPoint protocol was implemented, but we do now. This is not a semantic change to FloatingPoint, which has always bound IEEE-754 arithmetic types, for which this constraint would necessarily hold, but it does effect the type system. For example, currently the following function does not type check: ~~~~ func foo<T>(x: T) -> T where T: FloatingPoint { var r = x.remainder(dividingBy: 1) return r.magnitude } ~~~~ with this change, it compiles correctly.
1 parent 359385b commit 7208f96

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,8 @@ word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
167167
/// print("Average: \(average)°F in \(validTemps.count) " +
168168
/// "out of \(tempsFahrenheit.count) observations.")
169169
/// // Prints "Average: 74.84°F in 5 out of 7 observations."
170-
public protocol FloatingPoint: SignedNumeric, Strideable, Hashable {
171-
172-
// For the minimumMagnitude and maximumMagnitude methods
173-
/// A type that can represent the absolute value of any possible value of the
174-
/// conforming type.
175-
associatedtype Magnitude = Self
170+
public protocol FloatingPoint : SignedNumeric, Strideable, Hashable
171+
where Magnitude == Self {
176172

177173
/// A type that can represent any written exponent.
178174
associatedtype Exponent: SignedInteger

0 commit comments

Comments
 (0)