-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNBKDoubleWidth+Subtraction.swift
33 lines (27 loc) · 1.41 KB
/
NBKDoubleWidth+Subtraction.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//=----------------------------------------------------------------------------=
// This source file is part of the Numberick open source project.
//
// Copyright (c) 2023 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
import NBKCoreKit
//*============================================================================*
// MARK: * NBK x Double Width x Subtraction
//*============================================================================*
extension NBKDoubleWidth {
//=------------------------------------------------------------------------=
// MARK: Transformations x Overflow
//=------------------------------------------------------------------------=
@inlinable public mutating func subtractReportingOverflow(_ other: Self) -> Bool {
var overflow = self.low.subtractReportingOverflow(other.low) as Bool
overflow = overflow && self.high.subtractReportingOverflow(1 as Digit)
return overflow != self.high.subtractReportingOverflow(other.high)
}
@inlinable public func subtractingReportingOverflow(_ other: Self) -> PVO<Self> {
var partialValue = self
let overflow: Bool = partialValue.subtractReportingOverflow(other)
return PVO(partialValue, overflow)
}
}