Created
May 21, 2015 15:11
Revisions
-
fcanas created this gist
May 21, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ public struct Distance :NumericType { public var value :Double public init(_ value: Double) { self.value = value } } extension Distance :IntegerLiteralConvertible { public init(integerLiteral: IntegerLiteralType) { self.init(Double(integerLiteral)) } } extension Distance :FloatLiteralConvertible { public init(floatLiteral: FloatLiteralType) { self.init(Double(floatLiteral)) } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ public protocol NumericType : Comparable, FloatLiteralConvertible, IntegerLiteralConvertible, SignedNumberType { var value :Double { set get } init(_ value: Double) } public func % <T :NumericType> (lhs: T, rhs: T) -> T { return T(lhs.value % rhs.value) } public func + <T :NumericType> (lhs: T, rhs: T) -> T { return T(lhs.value + rhs.value) } public func - <T :NumericType> (lhs: T, rhs: T) -> T { return T(lhs.value - rhs.value) } public func < <T :NumericType> (lhs: T, rhs: T) -> Bool { return lhs.value < rhs.value } public func == <T :NumericType> (lhs: T, rhs: T) -> Bool { return lhs.value == rhs.value } public prefix func - <T: NumericType> (number: T) -> T { return T(-number.value) } public func += <T :NumericType> (inout lhs: T, rhs: T) { lhs.value = lhs.value + rhs.value } public func -= <T :NumericType> (inout lhs: T, rhs: T) { lhs.value = lhs.value - rhs.value }