Skip to content

Instantly share code, notes, and snippets.

@anisoptera
Last active August 17, 2022 09:40
Show Gist options
  • Save anisoptera/5708afc32454ed868363 to your computer and use it in GitHub Desktop.
Save anisoptera/5708afc32454ed868363 to your computer and use it in GitHub Desktop.
The overloads I've been dying to write since I started working with NSDecimalNumbers.
// The overloads I've been dying to write since I started working with NSDecimalNumbers.
import Foundation
@infix func > (left:NSDecimalNumber, right:NSDecimalNumber) -> Bool
{
return left.compare(right) == NSComparisonResult.OrderedDescending
}
@infix func < (left:NSDecimalNumber, right:NSDecimalNumber) -> Bool
{
return left.compare(right) == NSComparisonResult.OrderedAscending
}
@infix func >= (left:NSDecimalNumber, right:NSDecimalNumber) -> Bool
{
return left.compare(right) != NSComparisonResult.OrderedAscending
}
@infix func <= (left:NSDecimalNumber, right:NSDecimalNumber) -> Bool
{
return left.compare(right) != NSComparisonResult.OrderedDescending
}
@infix func + (left:NSDecimalNumber, right:NSDecimalNumber) -> NSDecimalNumber
{
return left.decimalNumberByAdding(right)
}
@infix func * (left:NSDecimalNumber, right:NSDecimalNumber) -> NSDecimalNumber
{
return left.decimalNumberByMultiplyingBy(right)
}
@infix func - (left:NSDecimalNumber, right:NSDecimalNumber) -> NSDecimalNumber
{
return left.decimalNumberBySubtracting(right)
}
@infix func / (left:NSDecimalNumber, right:NSDecimalNumber) -> NSDecimalNumber
{
return left.decimalNumberByDividingBy(right)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment