-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NBKCoreKit] Modular multiplicative inverse.
- Loading branch information
Showing
2 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Tests/NBKCoreKitBenchmarks/Private/NBKProperBinaryInteger+ModularMultiplicativeInverse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//=----------------------------------------------------------------------------= | ||
// 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. | ||
//=----------------------------------------------------------------------------= | ||
|
||
#if !DEBUG | ||
|
||
import NBKCoreKit | ||
import XCTest | ||
|
||
private typealias W = [UInt] | ||
private typealias X = [UInt64] | ||
private typealias Y = [UInt32] | ||
|
||
//*============================================================================* | ||
// MARK: * NBK x Proper Binary Integer x Modular Multiplicative Inverse | ||
//*============================================================================* | ||
|
||
final class NBKProperBinaryIntegerBenchmarksOnModularMultiplicativeInverse: XCTestCase { | ||
|
||
typealias T = NBK.PBI | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests x Binary Algorithm | ||
//=------------------------------------------------------------------------= | ||
|
||
func testInt8s() { | ||
for _ in 0 ..< 50 { | ||
for lhs in Int8.min ... Int8.max { | ||
for rhs in Int8.min ... Int8.max { | ||
NBK.blackHole(T.modularMultiplicativeInverse(of: lhs, mod: rhs)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func testUInt8s() { | ||
for _ in 0 ..< 50 { | ||
for lhs in UInt8.min ... UInt8.max { | ||
for rhs in UInt8.min ... UInt8.max { | ||
NBK.blackHole(T.modularMultiplicativeInverse(of: lhs, mod: rhs)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |