Skip to content

Commit 95d76cd

Browse files
Minor improvements to CGFloat (swiftlang#21090)
* Minor improvements to CGFloat Apparently init(exactly:) was never implemented for CGFloat, so let's fix that. Also includes minor cleanup for the .magnitude property. * Add transparent annotations to some other CGFloat things.
1 parent aa4745a commit 95d76cd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

stdlib/public/Darwin/CoreGraphics/CGFloat.swift.gyb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ public struct CGFloat {
6161
}
6262

6363
extension CGFloat : SignedNumeric {
64-
// FIXME(integers): implement properly
64+
65+
@_transparent
6566
public init?<T : BinaryInteger>(exactly source: T) {
66-
fatalError()
67+
guard let native = NativeType(exactly: source) else { return nil }
68+
self.native = native
6769
}
6870

6971
@_transparent
7072
public var magnitude: CGFloat {
71-
return CGFloat(Swift.abs(native))
73+
return CGFloat(native.magnitude)
7274
}
7375

7476
}
@@ -202,6 +204,7 @@ extension CGFloat : BinaryFloatingPoint {
202204
return CGFloat(native.nextUp)
203205
}
204206

207+
@_transparent
205208
public mutating func negate() {
206209
native.negate()
207210
}
@@ -271,22 +274,27 @@ extension CGFloat : BinaryFloatingPoint {
271274
return native.isFinite
272275
}
273276

277+
@_transparent
274278
public var isZero: Bool {
275279
return native.isZero
276280
}
277281

282+
@_transparent
278283
public var isSubnormal: Bool {
279284
return native.isSubnormal
280285
}
281286

287+
@_transparent
282288
public var isInfinite: Bool {
283289
return native.isInfinite
284290
}
285291

292+
@_transparent
286293
public var isNaN: Bool {
287294
return native.isNaN
288295
}
289296

297+
@_transparent
290298
public var isSignalingNaN: Bool {
291299
return native.isSignalingNaN
292300
}
@@ -296,18 +304,22 @@ extension CGFloat : BinaryFloatingPoint {
296304
fatalError("unavailable")
297305
}
298306

307+
@_transparent
299308
public var isCanonical: Bool {
300309
return true
301310
}
302311

312+
@_transparent
303313
public var floatingPointClass: FloatingPointClassification {
304314
return native.floatingPointClass
305315
}
306316

317+
@_transparent
307318
public var binade: CGFloat {
308319
return CGFloat(native.binade)
309320
}
310321

322+
@_transparent
311323
public var significandWidth: Int {
312324
return native.significandWidth
313325
}

0 commit comments

Comments
 (0)