Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.