Skip to content

Instantly share code, notes, and snippets.

@erica
Last active July 20, 2024 01:01
Show Gist options
  • Save erica/efc9f1df7a43350cc31b to your computer and use it in GitHub Desktop.
Save erica/efc9f1df7a43350cc31b to your computer and use it in GitHub Desktop.
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