-
-
Save dlo/04fa7a7e756ad676a0f73a65bf3b2c3b to your computer and use it in GitHub Desktop.
NSDecimalNumber Additions for Swift 3 - Updated
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 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.multiplying(by: NSDecimalNumber(mantissa: 1, exponent: 0, isNegative: true)) | |
} | |
public func +(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.adding(rhs) | |
} | |
public func -(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.subtracting(rhs) | |
} | |
public func *(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.multiplying(by: rhs) | |
} | |
public func /(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber { | |
return lhs.dividing(by: rhs) | |
} | |
public func ^(lhs: NSDecimalNumber, rhs: Int) -> NSDecimalNumber { | |
return lhs.raising(toPower: rhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment