Created
July 3, 2016 17:57
-
-
Save akesson/d4ccaaca580cf493a51b6a619304cc7f to your computer and use it in GitHub Desktop.
A little test to make a Percent struct wrapping a Float (could be generic Float/Double)
This file contains hidden or 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
import Foundation | |
public struct Percent { | |
private var _val: Float | |
} | |
public func == (left: Percent, right: Percent) -> Bool { | |
return left._val == right._val | |
} | |
public func < (left: Percent, right: Percent) -> Bool { | |
return left._val < right._val | |
} | |
public prefix func -(x: Percent) -> Percent { | |
return Percent(floatLiteral: -x._val) | |
} | |
public func -(lhs: Percent, rhs: Percent) -> Percent { | |
return Percent(floatLiteral: lhs._val - rhs._val) | |
} | |
extension Percent: Comparable { | |
} | |
extension Percent: Hashable { | |
public var hashValue: Int { | |
return _val.hashValue | |
} | |
} | |
extension Percent: IntegerLiteralConvertible { | |
public init(integerLiteral value: Int) { | |
_val = Float(value) | |
} | |
} | |
extension Percent: FloatLiteralConvertible { | |
public init(floatLiteral value: Float) { | |
_val = Float(value) | |
} | |
} | |
extension Percent: SignedNumberType { | |
} | |
extension Percent: AbsoluteValuable { | |
public static func abs(x: Percent) -> Percent { | |
return Percent(floatLiteral: Float.abs(x._val)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment