Skip to content

Commit

Permalink
add += and -=
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed May 21, 2024
1 parent aa68f29 commit 44a5c9d
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Sources/TonSdkSwift/Types/Coins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ extension Coins: Equatable, Comparable, Hashable {
}
}

// public static func <<= <RHS>(lhs: inout Coins, rhs: RHS) where RHS : BinaryInteger {
// lhs._nanoValue <<= rhs
// }
//
// public static func >>= <RHS>(lhs: inout Coins, rhs: RHS) where RHS : BinaryInteger {
// lhs._nanoValue >>= rhs
// }
public static func += (lhs: inout Coins, rhs: Coins) {
let result = lhs + rhs
lhs._nanoValue = result.nanoValue
lhs._decimals = result.decimals
}

public static func -= (lhs: inout Coins, rhs: Coins) {
let result = lhs - rhs
lhs._nanoValue = result.nanoValue
lhs._decimals = result.decimals
}

public static func /= (lhs: inout Coins, rhs: Coins) {
let result = lhs / rhs
Expand All @@ -197,6 +201,7 @@ extension Coins: Equatable, Comparable, Hashable {
lhs._decimals = result.decimals
}

#warning("Add additional operators")
// public static func &= (lhs: inout Coins, rhs: Coins) {
// lhs._nanoValue &= rhs.nanoValue
// }
Expand All @@ -212,7 +217,15 @@ extension Coins: Equatable, Comparable, Hashable {
// prefix public static func ~ (x: Coins) -> Coins {
// .init(nanoValue: ~x.nanoValue, decimals: x.decimals)
// }

//
// public static func <<= <RHS>(lhs: inout Coins, rhs: RHS) where RHS : BinaryInteger {
// lhs._nanoValue <<= rhs
// }
//
// public static func >>= <RHS>(lhs: inout Coins, rhs: RHS) where RHS : BinaryInteger {
// lhs._nanoValue >>= rhs
// }

public static func * (lhs: Coins, rhs: Coins) -> Coins {
if lhs.decimals > rhs.decimals {
return .init(nanoValue: (lhs.nanoValue * rhs.nanoValue) / BigInt(10**(rhs.decimals)), decimals: lhs.decimals)
Expand Down

0 comments on commit 44a5c9d

Please sign in to comment.