Last active
July 20, 2024 01:01
-
-
Save erica/efc9f1df7a43350cc31b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol FloatConvertible { | |
var doubleValue: Double { get } | |
var floatValue: Float { get } | |
var intValue: Int { get } | |
var CGFloatValue: CGFloat { get } | |
} | |
public extension FloatConvertible { | |
public var floatValue: Float {get {return Float(doubleValue)}} | |
public var intValue: Int {get {return lrint(doubleValue - 0.5)}} | |
public var CGFloatValue: CGFloat {get {return CGFloat(doubleValue)}} | |
} | |
extension CGFloat: FloatConvertible {public var doubleValue : Double {return Double(self)}} | |
extension Float: FloatConvertible {public var doubleValue : Double {return Double(self)}} | |
extension Double: FloatConvertible {public var doubleValue : Double {return self}} | |
extension Int: FloatConvertible {public var doubleValue : Double {return Double(self)}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment