-
-
Save grgcombs/bd71256c916289421a03 to your computer and use it in GitHub Desktop.
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 | |
// MARK: - Comparable | |
extension NSDecimalNumber: Comparable {} | |
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool { | |
return lhs.compare(rhs) == .OrderedSame | |
} | |
public func <(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool { | |
return lhs.compare(rhs) == .OrderedAscending | |
} | |
// MARK: - Arithmetic Operators | |
public prefix func -(value: NSDecimalNumber) -> NSDecimalNumber { | |
return value.decimalNumberByMultiplyingBy(NSDecimalNumber(mantissa: 1, exponent: 0, isNegative: true)) | |
} | |
public func +(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.decimalNumberByAdding(rhs) | |
} | |
public func -(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.decimalNumberBySubtracting(rhs) | |
} | |
public func *(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.decimalNumberByMultiplyingBy(rhs) | |
} | |
public func /(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.decimalNumberByDividingBy(rhs) | |
} | |
public func ^(lhs: NSDecimalNumber, rhs: Int) -> NSDecimalNumber { | |
return lhs.decimalNumberByRaisingToPower(rhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment