Skip to content

Commit

Permalink
Release 1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leif-ibsen committed Apr 20, 2023
1 parent ae9a61a commit bafec95
Show file tree
Hide file tree
Showing 62 changed files with 146 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BigInt requires Swift 5.0. It also requires that the Int and UInt types be 64 bi
In your projects Package.swift file add a dependency like<br/>

dependencies: [
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.10.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.11.0"),
]

<h2 id="ex"><b>Examples</b></h2>
Expand Down
26 changes: 26 additions & 0 deletions Sources/BigInt/BigInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,32 @@ public struct BInt: CustomStringConvertible, Comparable, Equatable, Hashable {
/// - Returns: If *self* and m are coprime, x such that (*self* \* x) mod m = 1
public func modInverse(_ m: Int) -> Int {
precondition(m > 0, "Modulus must be positive")
guard m > 1 else {
return 0
}
let tb = m.trailingZeroBitCount
if tb + m.leadingZeroBitCount == 63 {

precondition(self.isOdd, "No inverse modulus")

// Fast power of 2 implementation
// [KOC] - section 7

// Reduce mod m
let m = self.magnitude[0] & (1 << tb - 1)
let selfr = self.isNegative ? -Int(m) : Int(m)

var x = 0
var b = 1
for i in 0 ..< tb {
if b & 1 == 1 {
x |= 1 << i
b -= selfr
}
b >>= 1
}
return x
}
var a = 1
var g = self.mod(m)
var u = 0
Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/AdditionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class AdditionTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/BinomialTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class BinomialTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/BitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class BitTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ComparisonTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ComparisonTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ConstructorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ConstructorTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/DivExactTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class DivExactTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/DivModBZTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

// Test of the Burnikel-Ziegler division algorithm
// Tests are performed by verifying that the result of using Burnikel-Ziegler
Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/DivModTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class DivModTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ExpModTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ExpModTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/FFTTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class FFTTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/FactorialTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class FactorialTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/FibonacciTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class FibonacciTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/FractionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class FractionTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/GcdExtendedTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class GcdExtendedTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/GcdTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class GcdTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/IntMinMaxTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class IntMinMaxTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/JacobiTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class JacobiTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/KaratsubaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class KaratsubaTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/KroneckerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class KroneckerTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/LcmTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class LcmTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/LimbTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class LimbTest: XCTestCase {

Expand Down
13 changes: 13 additions & 0 deletions Tests/BigIntTests/ModInverseTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ModInverseTest: XCTestCase {

Expand Down Expand Up @@ -64,4 +65,16 @@ class ModInverseTest: XCTestCase {
XCTAssertEqual((-BInt.THREE).modInverse(BInt.ONE), BInt.ZERO)
}

func test3() {
let x1 = BInt.ONE << 20 + 1
let x2 = BInt.ONE << 200 + 1
for i in 0 ... 62 {
let m = 1 << i
XCTAssertEqual(BInt(x1.modInverse(m)), x1.modInverse(BInt(m)))
XCTAssertEqual(BInt((-x1).modInverse(m)), (-x1).modInverse(BInt(m)))
XCTAssertEqual(BInt(x2.modInverse(m)), x2.modInverse(BInt(m)))
XCTAssertEqual(BInt((-x2).modInverse(m)), (-x2).modInverse(BInt(m)))
}
}

}
1 change: 1 addition & 0 deletions Tests/BigIntTests/MulSquareTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class MulSquareTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/MultiplicationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class MultiplicationTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/PerformanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class PerformanceTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/PrimeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class PrimeTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/RootTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class RootTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ShiftTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ShiftTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/SubtractionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class SubtractionTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ToByteArrayTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ToByteArrayTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ToStringTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ToStringTest: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/BigIntTests/ToomCookTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
@testable import BigInt

class ToomCookTest: XCTestCase {

Expand Down
9 changes: 0 additions & 9 deletions Tests/BigIntTests/XCTestManifests.swift

This file was deleted.

6 changes: 3 additions & 3 deletions docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Structures Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html"> Docs</a> (100% documented)</p>
<p><a href="index.html">BigInt Docs</a> (100% documented)</p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand All @@ -27,7 +27,7 @@
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html"> Reference</a>
<a href="index.html">BigInt Reference</a>
<img id="carat" src="img/carat.png" alt=""/>
Structures Reference
</p>
Expand Down Expand Up @@ -145,7 +145,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2023-04-12)</p>
<p>&copy; 2023 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2023-04-19)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
6 changes: 3 additions & 3 deletions docs/Structs/BFraction.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="BFraction Structure Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html"> Docs</a> (100% documented)</p>
<p><a href="../index.html">BigInt Docs</a> (100% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand All @@ -27,7 +27,7 @@
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="../index.html"> Reference</a>
<a href="../index.html">BigInt Reference</a>
<img id="carat" src="../img/carat.png" alt=""/>
BFraction Structure Reference
</p>
Expand Down Expand Up @@ -5179,7 +5179,7 @@ <h4>Return Value</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2023-04-12)</p>
<p>&copy; 2023 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2023-04-19)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit bafec95

Please sign in to comment.