-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNBKFlexibleWidth.swift
50 lines (39 loc) · 1.77 KB
/
NBKFlexibleWidth.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//=----------------------------------------------------------------------------=
// 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
import NBKFlexibleWidthKit
import XCTest
private typealias X = [UInt]
private typealias X64 = [UInt64]
private typealias X32 = [UInt32]
//*============================================================================*
// MARK: * NBK x Flexible Width x UIntXL
//*============================================================================*
extension NBKFlexibleWidth.Magnitude {
//=------------------------------------------------------------------------=
// MARK: Constants
//=------------------------------------------------------------------------=
static let min256 = Self(x64:[ 0, 0, 0, 0] as X64)
static let max256 = Self(x64:[~0, ~0, ~0, ~0] as X64)
static let basket: [Self] = (-5 ... 5).lazy.map(UInt.init(bitPattern:)).flatMap({[
Self(words:[$0 ] as X),
Self(words:[$0, $0 &+ 1 ] as X),
Self(words:[$0, $0 &+ 1, $0 &+ 2 ] as X),
Self(words:[$0, $0 &+ 1, $0 &+ 2, $0 &+ 3] as X),
]})
//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=
init(x32: [UInt32]) {
self.init(words: NBKChunkedInt(x32))
}
init(x64: [UInt64]) {
self.init(words: NBKChunkedInt(x64))
}
}