mirror of
https://github.com/lil-org/tokenary.git
synced 2025-01-05 20:16:25 +03:00
28 lines
689 B
Swift
28 lines
689 B
Swift
//
|
|
// This source file is part of the Web3Swift.io open source project
|
|
// Copyright 2018 The Web3Swift Authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// BigUInt.swift
|
|
//
|
|
// Created by Timofey Solonin on 23/05/2018
|
|
//
|
|
|
|
import BigInt
|
|
import Foundation
|
|
|
|
extension BigUInt {
|
|
|
|
internal func subtractSafely(subtrahend: BigUInt) throws -> BigUInt {
|
|
let difference = self.subtractingReportingOverflow(subtrahend)
|
|
guard difference.overflow == false else {
|
|
throw IntegerOverflow(
|
|
firstTerm: self,
|
|
secondTerm: subtrahend,
|
|
operation: "subtraction"
|
|
)
|
|
}
|
|
return difference.partialValue
|
|
}
|
|
|
|
} |