├── .swift-version ├── Carthage └── Build │ ├── Mac │ ├── BigNumber.framework │ │ ├── Versions │ │ │ ├── Current │ │ │ └── A │ │ │ │ ├── Modules │ │ │ │ ├── module.modulemap │ │ │ │ └── BigNumber.swiftmodule │ │ │ │ │ ├── x86_64.swiftdoc │ │ │ │ │ └── x86_64.swiftmodule │ │ │ │ ├── BigNumber │ │ │ │ ├── Resources │ │ │ │ └── Info.plist │ │ │ │ └── Headers │ │ │ │ └── BigNumber-Swift.h │ │ ├── Headers │ │ ├── Modules │ │ ├── BigNumber │ │ └── Resources │ └── BigNumber.framework.dSYM │ │ └── Contents │ │ ├── Resources │ │ └── DWARF │ │ │ └── BigNumber │ │ └── Info.plist │ └── iOS │ ├── BigNumber.framework │ ├── BigNumber │ ├── Modules │ │ ├── module.modulemap │ │ └── BigNumber.swiftmodule │ │ │ ├── arm64.swiftdoc │ │ │ ├── x86_64.swiftdoc │ │ │ ├── arm64.swiftmodule │ │ │ └── x86_64.swiftmodule │ ├── Info.plist │ └── Headers │ │ ├── BigNumber_iOS.h │ │ └── BigNumber-Swift.h │ └── BigNumber.framework.dSYM │ └── Contents │ ├── Resources │ └── DWARF │ │ └── BigNumber │ └── Info.plist ├── docs ├── img │ ├── gh.png │ ├── carat.png │ ├── dash.png │ └── spinner.gif ├── docsets │ ├── BigNumber.tgz │ ├── BigNumber.xml │ └── BigNumber.docset │ │ └── Contents │ │ ├── Resources │ │ ├── docSet.dsidx │ │ └── Documents │ │ │ ├── img │ │ │ ├── gh.png │ │ │ ├── carat.png │ │ │ ├── dash.png │ │ │ └── spinner.gif │ │ │ ├── js │ │ │ ├── jazzy.js │ │ │ └── jazzy.search.js │ │ │ ├── css │ │ │ ├── highlight.css │ │ │ └── jazzy.css │ │ │ ├── Extensions │ │ │ ├── Int.html │ │ │ └── Double.html │ │ │ └── Extensions.html │ │ └── Info.plist ├── js │ ├── jazzy.js │ └── jazzy.search.js ├── css │ ├── highlight.css │ └── jazzy.css ├── Extensions │ ├── Int.html │ └── Double.html └── Extensions.html ├── Swift-BigNumber.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ ├── xcbaselines │ └── F646295B1FF017EA0074A180.xcbaseline │ │ ├── Info.plist │ │ └── 9D27035E-0C66-4C91-8299-009DD28C700B.plist │ └── xcschemes │ ├── BigNumber.xcscheme │ └── BigNumber-iOS.xcscheme ├── .github └── workflows │ └── swift.yml ├── Package.swift ├── BigNumber-iOS ├── BigNumber_iOS.h └── Info.plist ├── Testing └── Info.plist ├── Tests ├── Info.plist ├── Test_String_Conversions.swift ├── MG Math Tests.swift ├── MG Matrix Tests.swift ├── Test_BIntMath.swift ├── Test_Advanced_Math.swift ├── Test_Initialization.swift ├── BIntTests.swift └── Test_Basic_Math.swift ├── Sources └── Info.plist ├── LICENSE ├── Tools ├── MG IO.swift ├── MG QueueDispatch.swift ├── MG Complex.swift ├── MG Storage.swift ├── MG Benchmark Tools.swift ├── MG SuperSwift.swift └── MG Math.swift ├── generate-docs.sh ├── .gitignore ├── main.swift ├── Resources └── longNumbers.json ├── BigNumber.podspec ├── Benchmarks └── Benchmarks.swift └── README.md /.swift-version: -------------------------------------------------------------------------------- 1 | 4.2 2 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Headers: -------------------------------------------------------------------------------- 1 | Versions/Current/Headers -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Modules: -------------------------------------------------------------------------------- 1 | Versions/Current/Modules -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/BigNumber: -------------------------------------------------------------------------------- 1 | Versions/Current/BigNumber -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Resources: -------------------------------------------------------------------------------- 1 | Versions/Current/Resources -------------------------------------------------------------------------------- /docs/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/img/gh.png -------------------------------------------------------------------------------- /docs/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/img/carat.png -------------------------------------------------------------------------------- /docs/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/img/dash.png -------------------------------------------------------------------------------- /docs/img/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/img/spinner.gif -------------------------------------------------------------------------------- /docs/docsets/BigNumber.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.tgz -------------------------------------------------------------------------------- /docs/docsets/BigNumber.xml: -------------------------------------------------------------------------------- 1 | 2.1.1https://mkrd.github.io/BigNumber/reference/docsets/BigNumber.tgz 2 | -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/BigNumber: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/BigNumber -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module BigNumber { 2 | header "BigNumber-Swift.h" 3 | requires objc 4 | } 5 | -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/Info.plist -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module BigNumber { 2 | header "BigNumber-Swift.h" 3 | requires objc 4 | } 5 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/BigNumber: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/Mac/BigNumber.framework/Versions/A/BigNumber -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/docSet.dsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.docset/Contents/Resources/docSet.dsidx -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/gh.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/carat.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/dash.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/spinner.gif -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework.dSYM/Contents/Resources/DWARF/BigNumber: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/Mac/BigNumber.framework.dSYM/Contents/Resources/DWARF/BigNumber -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework.dSYM/Contents/Resources/DWARF/BigNumber: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework.dSYM/Contents/Resources/DWARF/BigNumber -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/arm64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/arm64.swiftdoc -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/x86_64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/x86_64.swiftdoc -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/arm64.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/arm64.swiftmodule -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/x86_64.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/iOS/BigNumber.framework/Modules/BigNumber.swiftmodule/x86_64.swiftmodule -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/Modules/BigNumber.swiftmodule/x86_64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/Mac/BigNumber.framework/Versions/A/Modules/BigNumber.swiftmodule/x86_64.swiftdoc -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/Modules/BigNumber.swiftmodule/x86_64.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twodayslate/Swift-Big-Integer/master/Carthage/Build/Mac/BigNumber.framework/Versions/A/Modules/BigNumber.swiftmodule/x86_64.swiftmodule -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.github/workflows/swift.yml: -------------------------------------------------------------------------------- 1 | name: Swift 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: macos-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Build 17 | run: swift build -v 18 | - name: Run tests 19 | run: swift test -v 20 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.2 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "BigNumber", 6 | products: [ 7 | .library( 8 | name: "BigNumber", 9 | targets: ["BigNumber"]), 10 | ], 11 | dependencies: [], 12 | targets: [ 13 | .target( 14 | name: "BigNumber", 15 | dependencies: [], 16 | path: "Sources"), 17 | .testTarget( 18 | name: "BigNumberTests", 19 | dependencies: ["BigNumber"], 20 | path: "Tests"), 21 | ] 22 | ) 23 | -------------------------------------------------------------------------------- /BigNumber-iOS/BigNumber_iOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // BigNumber_iOS.h 3 | // BigNumber-iOS 4 | // 5 | // Created by yuzushioh on 2018/02/23. 6 | // Copyright © 2018 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for BigNumber_iOS. 12 | FOUNDATION_EXPORT double BigNumber_iOSVersionNumber; 13 | 14 | //! Project version string for BigNumber_iOS. 15 | FOUNDATION_EXPORT const unsigned char BigNumber_iOSVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Headers/BigNumber_iOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // BigNumber_iOS.h 3 | // BigNumber-iOS 4 | // 5 | // Created by yuzushioh on 2018/02/23. 6 | // Copyright © 2018 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for BigNumber_iOS. 12 | FOUNDATION_EXPORT double BigNumber_iOSVersionNumber; 13 | 14 | //! Project version string for BigNumber_iOS. 15 | FOUNDATION_EXPORT const unsigned char BigNumber_iOSVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | com.jazzy.bignumber 7 | CFBundleName 8 | BigNumber 9 | DocSetPlatformFamily 10 | bignumber 11 | isDashDocset 12 | 13 | dashIndexFilePath 14 | index.html 15 | isJavaScriptEnabled 16 | 17 | DashDocSetFamily 18 | dashtoc 19 | 20 | 21 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework.dSYM/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.xcode.dsym.com.mkrd.BigNumber 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundlePackageType 12 | dSYM 13 | CFBundleSignature 14 | ???? 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleVersion 18 | 1 19 | 20 | 21 | -------------------------------------------------------------------------------- /Testing/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework.dSYM/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.xcode.dsym.com.yuzushioh.BigNumber-iOS 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundlePackageType 12 | dSYM 13 | CFBundleSignature 14 | ???? 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleVersion 18 | 1 19 | 20 | 21 | -------------------------------------------------------------------------------- /Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /BigNumber-iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/Test_String_Conversions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_String_Conversions.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_String_Conversions: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func test_description_BInt() { 23 | for n in -4...4 24 | { 25 | XCTAssert(n.description == BInt(n).description) 26 | XCTAssert(n.description == BInt(n.description)!.description) 27 | } 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Sources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2017 Marcel Kröker. All rights reserved. 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Tests/MG Math Tests.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * |||||||| MG Math Tests ||||||||||||||||||||||||||||||||||||||| 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 05.09.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | #if !SWIFT_PACKAGE 11 | public class MG_Math_Tests 12 | { 13 | static func test_primesTo() 14 | { 15 | for i in 2...200 16 | { 17 | let primes = math.primesThrough(i) 18 | 19 | for j in 2...i 20 | { 21 | if math.isPrime(j) 22 | { 23 | precondition(primes.contains(j), "\(j) is prime but not in \(primes), i = \(i)") 24 | } 25 | else 26 | { 27 | precondition(!primes.contains(j), "\(j) is not prime but in \(primes), i = \(i)") 28 | } 29 | } 30 | } 31 | 32 | // benchmarkPrint(title: "primes") { 33 | // let n = math.primesThrough(150_000_000) 34 | // print("\(Double(n.count) / 1_000_000.0) Million") 35 | // } 36 | } 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcbaselines/F646295B1FF017EA0074A180.xcbaseline/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | runDestinationsByUUID 6 | 7 | 9D27035E-0C66-4C91-8299-009DD28C700B 8 | 9 | localComputer 10 | 11 | busSpeedInMHz 12 | 100 13 | cpuCount 14 | 1 15 | cpuKind 16 | Intel Core i7 17 | cpuSpeedInMHz 18 | 2800 19 | logicalCPUCoresPerPackage 20 | 4 21 | modelCode 22 | MacBookPro11,1 23 | physicalCPUCoresPerPackage 24 | 2 25 | platformIdentifier 26 | com.apple.platform.macosx 27 | 28 | targetArchitecture 29 | x86_64 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 mkrd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Tools/MG IO.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG IO.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 27.05.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | /** 12 | Stop execution and log keyboard input. Returns input after enter was 13 | pressed. 14 | */ 15 | public func getKeyboardInput() -> String 16 | { 17 | let keyboard = FileHandle.standardInput 18 | 19 | let input = String( 20 | data: keyboard.availableData, 21 | encoding: String.Encoding.utf8 22 | )! 23 | 24 | return input.trimmingCharacters(in: CharacterSet(["\n"])) 25 | } 26 | 27 | /** 28 | Stop execution and log keyboard input. Returns input as Int after a vaild 29 | Integer was entered. Otherwise, it promts the user again until a vaild 30 | Integer was entered. 31 | */ 32 | public func getKeyboardInputAsInt() -> Int 33 | { 34 | while true 35 | { 36 | let input = getKeyboardInput() 37 | 38 | if let asInt = Int(input) { return asInt } 39 | 40 | print("Input must be an Integer but was: \"\(input)\"") 41 | print("Enter a vaild number:") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/MG Matrix Tests.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Matrix Tests.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 26.10.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | #if !SWIFT_PACKAGE 11 | public class MG_Matrix_Tests 12 | { 13 | static func testSparseMatrix() 14 | { 15 | // Make a random sparse matrix 16 | 17 | var M = Matrix( 18 | repeating: 0, 19 | rows: math.random(1...500), 20 | cols: math.random(1...500) 21 | ) 22 | 23 | for (i, j) in M 24 | { 25 | if math.random(0.0...1.0) <= 0.01 { M[i, j] = math.random(1...99) } 26 | } 27 | 28 | // Now, convert it to a SparseMatrix 29 | let S = SparseMatrix(M) 30 | 31 | // print("Dimension: \(M.rows)x\(M.cols)") 32 | // print("Sparse kbit: \(S.bitWidth / 1000)") 33 | // print("Normal kbit: \(M.bitWidth / 1000)") 34 | // let ratio = String(format: "%.1f", Double(M.bitWidth) / Double(S.bitWidth)) 35 | // print("Matrix needs \(ratio)x more Memory than SparseMatrix") 36 | 37 | for (i, j) in M 38 | { 39 | precondition(M[i, j] == S[i, j], "Error: A[\(i), \(j)] != S[\(i), \(j)])") 40 | } 41 | } 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Tools/MG QueueDispatch.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG QueueDispatch.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 25.12.15. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | public struct QueueDispatch 12 | { 13 | static var coreCount: Int 14 | { 15 | return ProcessInfo.processInfo.activeProcessorCount 16 | } 17 | 18 | /** 19 | Run trailing closure after a given time in seconds in background queue. 20 | */ 21 | static public func runAfterDelay(_ seconds: Double, _ closure: @escaping () -> ()) 22 | { 23 | let queue = DispatchQueue.global() 24 | 25 | queue.asyncAfter(deadline: DispatchTime.now() + seconds, execute: closure) 26 | } 27 | 28 | /** 29 | Dispatches closures and optionally waits for them to finish their 30 | execution before the caller can continue executing his code. 31 | */ 32 | static public func parallel(waitUnitAllFinished wait: Bool, closures: [() -> ()]) 33 | { 34 | let queue = OperationQueue() 35 | 36 | queue.maxConcurrentOperationCount = QueueDispatch.coreCount - (wait ? 0 : 1) 37 | 38 | for closure in closures 39 | { 40 | queue.addOperation(closure) 41 | } 42 | 43 | if wait { queue.waitUntilAllOperationsAreFinished() } 44 | } 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Tests/Test_BIntMath.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_BIntMath.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_BIntMath: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func test_gcd() 23 | { 24 | #if !SWIFT_PACKAGE 25 | for (a, b) in (0...50)><(0...50) 26 | { 27 | let steinGCD = BIntMath.gcd(BInt(a), BInt(b)) 28 | let euclidGCD = BIntMath.gcdEuclid(BInt(a), BInt(b)) 29 | XCTAssert(steinGCD == euclidGCD, "SteinGcd does not work") 30 | } 31 | let g1 = Storage.readResource("gcdTest1", inBundle: Bundle(for: type(of: self))) 32 | let g2 = Storage.readResource("gcdTest2", inBundle: Bundle(for: type(of: self))) 33 | XCTAssert(BIntMath.gcd(BInt(g1)!, BInt(g2)!) == 66) 34 | #endif 35 | 36 | for a in 0..<50 { 37 | for b in 0..<50 { 38 | let steinGCD = BIntMath.gcd(BInt(a), BInt(b)) 39 | let euclidGCD = BIntMath.gcdEuclid(BInt(a), BInt(b)) 40 | XCTAssertEqual(steinGCD, euclidGCD) 41 | } 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 17D47 7 | CFBundleDevelopmentRegion 8 | English 9 | CFBundleExecutable 10 | BigNumber 11 | CFBundleIdentifier 12 | com.mkrd.BigNumber 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | BigNumber 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSupportedPlatforms 22 | 23 | MacOSX 24 | 25 | CFBundleVersion 26 | 1 27 | DTCompiler 28 | com.apple.compilers.llvm.clang.1_0 29 | DTPlatformBuild 30 | 9C40b 31 | DTPlatformVersion 32 | GM 33 | DTSDKBuild 34 | 17C76 35 | DTSDKName 36 | macosx10.13 37 | DTXcode 38 | 0920 39 | DTXcodeBuild 40 | 9C40b 41 | NSHumanReadableCopyright 42 | Copyright © 2017 Marcel Kröker. All rights reserved. 43 | 44 | 45 | -------------------------------------------------------------------------------- /generate-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | command -v jazzy 4 | 5 | if [ $? != 0 ]; then 6 | echo "jazzy not found. Install jazzy:" 7 | echo "\t[sudo] gem install jazzy" 8 | exit 1 9 | fi 10 | 11 | set -e # don't print 12 | 13 | module="BigNumber" 14 | github="mkrd/Swift-Big-Integer" 15 | project="Swift-BigNumber.xcodeproj" 16 | scheme="BigNumber" 17 | 18 | # get version number from podspec 19 | version="$(egrep "^\s*s.version\s*" BigNumber.podspec | awk '{ gsub("\"", "", $3); print $3 }')" 20 | today="$(date '+%Y-%m-%d')" 21 | 22 | if git rev-parse "v$version" >/dev/null 2>&1; then 23 | # Use the tagged commit when we have one 24 | ref="v$version" 25 | else 26 | # Otherwise, use the current commit. 27 | ref="$(git rev-parse HEAD)" 28 | fi 29 | 30 | # since tagging releases doesn't happen very much - let's just use head 31 | ref="master" 32 | 33 | jazzy \ 34 | --clean \ 35 | --github_url "https://github.com/$github" \ 36 | --github-file-prefix "https://github.com/$github/tree/$ref" \ 37 | --module-version "$version" \ 38 | --xcodebuild-arguments "-project,$project,-scheme,$scheme" \ 39 | --module "$module" \ 40 | --root-url "https://mkrd.github.io/$module/reference/" \ 41 | --theme fullwidth \ 42 | --output docs \ 43 | --min-acl public\ 44 | --hide-documentation-coverage\ 45 | --copyright "[© 2018 BigNumber](https://github.com/mkrd/Swift-Big-Integer/blob/master/LICENSE). (Last updated: $today)" \ 46 | --author "mkrd" \ 47 | --author_url "https://github.com/mkrd" \ 48 | -------------------------------------------------------------------------------- /Tools/MG Complex.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Complex.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 06.11.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | public struct Complex 12 | { 13 | var (re, im): (Double, Double) 14 | 15 | init(re: Double, im: Double) 16 | { 17 | self.re = re 18 | self.im = im 19 | } 20 | 21 | var r: Double 22 | { 23 | get { return self.re } 24 | set { self.re = r } 25 | } 26 | 27 | var i: Double 28 | { 29 | get { return self.im } 30 | set { self.im = i } 31 | } 32 | } 33 | 34 | public func +(lhs: Complex, rhs: Complex) -> Complex 35 | { 36 | return Complex( 37 | re: lhs.re + rhs.re, 38 | im: lhs.im + rhs.im 39 | ) 40 | } 41 | 42 | public func -(lhs: Complex, rhs: Complex) -> Complex 43 | { 44 | return Complex( 45 | re: lhs.re + rhs.re, 46 | im: lhs.im + rhs.im 47 | ) 48 | } 49 | 50 | public func *(x: Complex, y: Complex) -> Complex 51 | { 52 | return Complex( 53 | re: x.re * y.re - x.im * y.im, 54 | im: x.im * y.re + x.re * y.im 55 | ) 56 | } 57 | 58 | public func /(x: Complex, y: Complex) -> Complex 59 | { 60 | let divisor = y.re * y.re + y.im * y.im 61 | return Complex( 62 | re: (x.re * y.re + x.im * y.im) / divisor, 63 | im: (x.im * y.re - x.re * y.im) / divisor 64 | ) 65 | } 66 | 67 | public func exp(_ x: Complex) -> Complex 68 | { 69 | let ea = Complex(re: pow(2.7, x.re), im: 0.0 ) 70 | let t = Complex(re: cos(x.im) , im: sin(x.im)) 71 | return ea * t 72 | } 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | .swiftpm 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | *.xcscmblueprint 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | 32 | ## Playgrounds 33 | timeline.xctimeline 34 | playground.xcworkspace 35 | 36 | # Swift Package Manager 37 | # 38 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 39 | # Packages/ 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 63 | 64 | fastlane/report.xml 65 | fastlane/screenshots 66 | 67 | .DS_Store 68 | -------------------------------------------------------------------------------- /docs/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | function toggleItem($link, $content) { 12 | var animationDuration = 300; 13 | $link.toggleClass('token-open'); 14 | $content.slideToggle(animationDuration); 15 | } 16 | 17 | function itemLinkToContent($link) { 18 | return $link.parent().parent().next(); 19 | } 20 | 21 | // On doc load + hash-change, open any targetted item 22 | function openCurrentItemIfClosed() { 23 | if (window.jazzy.docset) { 24 | return; 25 | } 26 | var $link = $(`.token[href="${location.hash}"]`); 27 | $content = itemLinkToContent($link); 28 | if ($content.is(':hidden')) { 29 | toggleItem($link, $content); 30 | } 31 | } 32 | 33 | $(openCurrentItemIfClosed); 34 | $(window).on('hashchange', openCurrentItemIfClosed); 35 | 36 | // On item link ('token') click, toggle its discussion 37 | $('.token').on('click', function(event) { 38 | if (window.jazzy.docset) { 39 | return; 40 | } 41 | var $link = $(this); 42 | toggleItem($link, itemLinkToContent($link)); 43 | 44 | // Keeps the document from jumping to the hash. 45 | var href = $link.attr('href'); 46 | if (history.pushState) { 47 | history.pushState({}, '', href); 48 | } else { 49 | location.hash = href; 50 | } 51 | event.preventDefault(); 52 | }); 53 | 54 | // Clicks on links to the current, closed, item need to open the item 55 | $("a:not('.token')").on('click', function() { 56 | if (location == this.href) { 57 | openCurrentItemIfClosed(); 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | function toggleItem($link, $content) { 12 | var animationDuration = 300; 13 | $link.toggleClass('token-open'); 14 | $content.slideToggle(animationDuration); 15 | } 16 | 17 | function itemLinkToContent($link) { 18 | return $link.parent().parent().next(); 19 | } 20 | 21 | // On doc load + hash-change, open any targetted item 22 | function openCurrentItemIfClosed() { 23 | if (window.jazzy.docset) { 24 | return; 25 | } 26 | var $link = $(`.token[href="${location.hash}"]`); 27 | $content = itemLinkToContent($link); 28 | if ($content.is(':hidden')) { 29 | toggleItem($link, $content); 30 | } 31 | } 32 | 33 | $(openCurrentItemIfClosed); 34 | $(window).on('hashchange', openCurrentItemIfClosed); 35 | 36 | // On item link ('token') click, toggle its discussion 37 | $('.token').on('click', function(event) { 38 | if (window.jazzy.docset) { 39 | return; 40 | } 41 | var $link = $(this); 42 | toggleItem($link, itemLinkToContent($link)); 43 | 44 | // Keeps the document from jumping to the hash. 45 | var href = $link.attr('href'); 46 | if (history.pushState) { 47 | history.pushState({}, '', href); 48 | } else { 49 | location.hash = href; 50 | } 51 | event.preventDefault(); 52 | }); 53 | 54 | // Clicks on links to the current, closed, item need to open the item 55 | $("a:not('.token')").on('click', function() { 56 | if (location == this.href) { 57 | openCurrentItemIfClosed(); 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcbaselines/F646295B1FF017EA0074A180.xcbaseline/9D27035E-0C66-4C91-8299-009DD28C700B.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | classNames 6 | 7 | BDoubleTests 8 | 9 | testPerformanceStringInit() 10 | 11 | com.apple.XCTPerformanceMetric_WallClockTime 12 | 13 | baselineAverage 14 | 0.52745 15 | baselineIntegrationDisplayName 16 | Local Baseline 17 | 18 | 19 | testPerformanceStringRadixInit() 20 | 21 | com.apple.XCTPerformanceMetric_WallClockTime 22 | 23 | baselineAverage 24 | 0.59005 25 | baselineIntegrationDisplayName 26 | Local Baseline 27 | 28 | 29 | 30 | BIntTests 31 | 32 | testPerformanceStringInit() 33 | 34 | com.apple.XCTPerformanceMetric_WallClockTime 35 | 36 | baselineAverage 37 | 0.28374 38 | baselineIntegrationDisplayName 39 | Local Baseline 40 | 41 | 42 | testPerformanceStringRadixInit() 43 | 44 | com.apple.XCTPerformanceMetric_WallClockTime 45 | 46 | baselineAverage 47 | 0.278 48 | baselineIntegrationDisplayName 49 | Local Baseline 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Tests/Test_Advanced_Math.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_Advanced_Math.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_Advanced_Math: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func test_Alternating_Series() 23 | { 24 | var b = BInt(0) 25 | for k in 0...100 26 | { 27 | b += (BInt(-1) ** k) * (BInt(5) ** k) 28 | } 29 | XCTAssert(b.rawValue.limbs == [0x28e3f37dc8c26cc9,0x9f59e568b211b961,0xd92c3dea0eea4010,0xf3d659f514]) 30 | XCTAssert(b.description == "6573840876841765045097738044023218580610053625908525039752324422200521") 31 | 32 | b = BInt(0) 33 | for k in 1...138 34 | { 35 | b += (BInt(k) ** k) - (BInt(137) ** k) 36 | } 37 | XCTAssert(b.rawValue.limbs == [17152098566286916563, 4974948639188066814, 4489317707884913023, 9306023348854241191, 458651883002965321, 3683521711743239055, 16851376351636449383, 741781077320468085, 800339803456222032, 13955889474532705287, 9986965365556055439, 6943506609237153382, 14193507606682829060, 2267111281450088010, 16370502465740827650, 1306853]) 38 | XCTAssert(b.description == "12735701500187047591959419733566858766853126946820718978070969024692885331213304930991162556374421032376469699828008508881075741782571348017377682034125474151722103219051041832160135737768757033144950631943320498343308408527570876037282172430879499586152728823468776739519354613957714873403358163") 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /docs/js/jazzy.search.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | var $typeahead = $('[data-typeahead]'); 3 | var $form = $typeahead.parents('form'); 4 | var searchURL = $form.attr('action'); 5 | 6 | function displayTemplate(result) { 7 | return result.name; 8 | } 9 | 10 | function suggestionTemplate(result) { 11 | var t = '
'; 12 | t += '' + result.name + ''; 13 | if (result.parent_name) { 14 | t += '' + result.parent_name + ''; 15 | } 16 | t += '
'; 17 | return t; 18 | } 19 | 20 | $typeahead.one('focus', function() { 21 | $form.addClass('loading'); 22 | 23 | $.getJSON(searchURL).then(function(searchData) { 24 | const searchIndex = lunr(function() { 25 | this.ref('url'); 26 | this.field('name'); 27 | this.field('abstract'); 28 | for (const [url, doc] of Object.entries(searchData)) { 29 | this.add({url: url, name: doc.name, abstract: doc.abstract}); 30 | } 31 | }); 32 | 33 | $typeahead.typeahead( 34 | { 35 | highlight: true, 36 | minLength: 3, 37 | autoselect: true 38 | }, 39 | { 40 | limit: 10, 41 | display: displayTemplate, 42 | templates: { suggestion: suggestionTemplate }, 43 | source: function(query, sync) { 44 | const lcSearch = query.toLowerCase(); 45 | const results = searchIndex.query(function(q) { 46 | q.term(lcSearch, { boost: 100 }); 47 | q.term(lcSearch, { 48 | boost: 10, 49 | wildcard: lunr.Query.wildcard.TRAILING 50 | }); 51 | }).map(function(result) { 52 | var doc = searchData[result.ref]; 53 | doc.url = result.ref; 54 | return doc; 55 | }); 56 | sync(results); 57 | } 58 | } 59 | ); 60 | $form.removeClass('loading'); 61 | $typeahead.trigger('focus'); 62 | }); 63 | }); 64 | 65 | var baseURL = searchURL.slice(0, -"search.json".length); 66 | 67 | $typeahead.on('typeahead:select', function(e, result) { 68 | window.location = baseURL + result.url; 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/js/jazzy.search.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | var $typeahead = $('[data-typeahead]'); 3 | var $form = $typeahead.parents('form'); 4 | var searchURL = $form.attr('action'); 5 | 6 | function displayTemplate(result) { 7 | return result.name; 8 | } 9 | 10 | function suggestionTemplate(result) { 11 | var t = '
'; 12 | t += '' + result.name + ''; 13 | if (result.parent_name) { 14 | t += '' + result.parent_name + ''; 15 | } 16 | t += '
'; 17 | return t; 18 | } 19 | 20 | $typeahead.one('focus', function() { 21 | $form.addClass('loading'); 22 | 23 | $.getJSON(searchURL).then(function(searchData) { 24 | const searchIndex = lunr(function() { 25 | this.ref('url'); 26 | this.field('name'); 27 | this.field('abstract'); 28 | for (const [url, doc] of Object.entries(searchData)) { 29 | this.add({url: url, name: doc.name, abstract: doc.abstract}); 30 | } 31 | }); 32 | 33 | $typeahead.typeahead( 34 | { 35 | highlight: true, 36 | minLength: 3, 37 | autoselect: true 38 | }, 39 | { 40 | limit: 10, 41 | display: displayTemplate, 42 | templates: { suggestion: suggestionTemplate }, 43 | source: function(query, sync) { 44 | const lcSearch = query.toLowerCase(); 45 | const results = searchIndex.query(function(q) { 46 | q.term(lcSearch, { boost: 100 }); 47 | q.term(lcSearch, { 48 | boost: 10, 49 | wildcard: lunr.Query.wildcard.TRAILING 50 | }); 51 | }).map(function(result) { 52 | var doc = searchData[result.ref]; 53 | doc.url = result.ref; 54 | return doc; 55 | }); 56 | sync(results); 57 | } 58 | } 59 | ); 60 | $form.removeClass('loading'); 61 | $typeahead.trigger('focus'); 62 | }); 63 | }); 64 | 65 | var baseURL = searchURL.slice(0, -"search.json".length); 66 | 67 | $typeahead.on('typeahead:select', function(e, result) { 68 | window.location = baseURL + result.url; 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /Tests/Test_Initialization.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_Initialization.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_Initialization: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func test_Initialization_BInt() 23 | { 24 | // Test if BInt stores limbs correctly 25 | XCTAssert(BInt(limbs: [0]).rawValue.limbs == [0]) 26 | XCTAssert(BInt(limbs: [0]).bitWidth == UInt64.bitWidth) 27 | 28 | // Test some interesting edge cases 29 | for n in [0, 1, -1, Int.max, Int.min] 30 | { 31 | XCTAssert(n.description == BInt(n).description) 32 | XCTAssert(n.bitWidth == BInt(n).bitWidth) // since Int.bitWidth == UInt64.bitWidth 33 | } 34 | 35 | let b = BInt(1) + BInt(limbs: [UInt64.max, UInt64.max, UInt64.max, UInt64.max]) 36 | XCTAssert(b.rawValue.limbs == [0, 0, 0, 0, 1]) 37 | XCTAssert(b.bitWidth == UInt64.bitWidth * 5) 38 | } 39 | 40 | func testBytes() 41 | { 42 | // Bytes and expected number 43 | // 0x0102030405 is 4328719365 in decimal 44 | let array: Bytes = [0x01, 0x02, 0x03, 0x04, 0x05] 45 | let expected: Int = 4328719365 46 | 47 | // Init from bytes (array) 48 | let b = BInt(bytes: array) 49 | XCTAssertEqual(b.description, expected.description) 50 | 51 | // Convert back to bytes 52 | let bytes = b.getBytes() 53 | XCTAssertEqual(bytes, array) 54 | } 55 | 56 | func testCodable() { 57 | for i in 0..<50 { 58 | let one = BInt(i) 59 | 60 | let json = try! JSONEncoder().encode(one) 61 | 62 | let my_one = try! JSONDecoder().decode(BInt.self, from: json) 63 | 64 | XCTAssertEqual(one, my_one) 65 | 66 | let rand = BInt(String(arc4random()), radix: 10) 67 | 68 | let rand_json = try! JSONEncoder().encode(rand) 69 | 70 | let my_rand = try! JSONDecoder().decode(BInt.self, from: rand_json) 71 | 72 | XCTAssertEqual(rand, my_rand) 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Run Benchmarks 4 | Benchmarks.BDoubleConverging() 5 | Benchmarks.exponentiation() 6 | Benchmarks.factorial() 7 | Benchmarks.fibonacci() 8 | Benchmarks.Matrix1() 9 | Benchmarks.mersennes() 10 | Benchmarks.BIntToString() 11 | Benchmarks.StringToBInt() 12 | //Benchmarks.permutationsAndCombinations() 13 | Benchmarks.multiplicationBalanced() 14 | Benchmarks.multiplicationUnbalanced() 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | //public struct PixelData { 27 | // var a:UInt8 = 255 28 | // var r:UInt8 29 | // var g:UInt8 30 | // var b:UInt8 31 | //} 32 | // 33 | //private let rgbColorSpace = CGColorSpaceCreateDeviceRGB() 34 | //private let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue) 35 | // 36 | //public func imageFromARGB32Bitmap(pixels:[PixelData], width: Int, height: Int) -> CGImage { 37 | // let bitsPerComponent: Int = 8 38 | // let bitsPerPixel: Int = 32 39 | // 40 | // assert(pixels.count == Int(width * height)) 41 | // 42 | // var data = pixels // Copy to mutable [] 43 | // let providerRef = CGDataProvider( 44 | // data: NSData(bytes: &data, length: data.count * MemoryLayout.size) 45 | // ) 46 | // 47 | // let cgim = CGImage( 48 | // width: width, 49 | // height: height, 50 | // bitsPerComponent: bitsPerComponent, 51 | // bitsPerPixel: bitsPerPixel, 52 | // bytesPerRow: width * MemoryLayout.size, 53 | // space: rgbColorSpace, 54 | // bitmapInfo: bitmapInfo, 55 | // provider: providerRef!, 56 | // decode: nil, 57 | // shouldInterpolate: true, 58 | // intent: CGColorRenderingIntent.defaultIntent 59 | // ) 60 | // return cgim! 61 | //} 62 | // 63 | // 64 | //@discardableResult 65 | //func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool { 66 | // guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypePNG, 1, nil) else { 67 | // print("ERR") 68 | // return false 69 | // 70 | // } 71 | // CGImageDestinationAddImage(destination, image, nil) 72 | // return CGImageDestinationFinalize(destination) 73 | //} 74 | // 75 | //func makeAndSave() 76 | //{ 77 | // let dimension = 4000 78 | // 79 | // 80 | // var pixels = [PixelData]() 81 | // 82 | // for i in 1...(dimension * dimension) 83 | // { 84 | // if math.isPrime(i) 85 | // { 86 | // pixels.append(PixelData(a: 255, r: 0, g: 0, b: 0)) 87 | // } 88 | // else 89 | // { 90 | // pixels.append(PixelData(a: 0, r: 255, g: 255, b: 255)) 91 | // } 92 | // } 93 | // 94 | // 95 | // let img = imageFromARGB32Bitmap(pixels: pixels, width: dimension, height: dimension) 96 | // 97 | // let writeURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!.appendingPathComponent("name.png") 98 | // 99 | // writeCGImage(img, to: writeURL) 100 | //} 101 | // 102 | //benchmarkAndPrint(title: "") 103 | //{ 104 | // makeAndSave() 105 | //} 106 | 107 | -------------------------------------------------------------------------------- /Tools/MG Storage.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Storage.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 09.10.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | 12 | public struct Storage 13 | { 14 | static func readResource(_ key: String, inBundle: Bundle = Bundle.main) -> String 15 | { 16 | if let path = inBundle.path(forResource: "longNumbers", ofType: "json", inDirectory: "Resources") 17 | { 18 | let data = try! Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) 19 | let jsonResult = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) 20 | if let jsonResult = jsonResult as? Dictionary 21 | { 22 | if let res = jsonResult[key] 23 | { 24 | return res 25 | } 26 | } 27 | } 28 | return "" 29 | } 30 | 31 | /// Write a datapoint to UserDefaults for the key "key". 32 | static func write(_ value: Any, forKey key: String) 33 | { 34 | UserDefaults.standard.set(value, forKey: key) 35 | UserDefaults.standard.synchronize() 36 | } 37 | 38 | /// Read a datapoint from UserDefaults with the key key. 39 | static func read(forkey key: String) -> Any? 40 | { 41 | return UserDefaults.standard.object(forKey: key) 42 | } 43 | 44 | /// Remove a datapoint from UserDefaults for the key key. 45 | static func remove(forKey key: String) 46 | { 47 | UserDefaults.standard.removeObject(forKey: key) 48 | } 49 | 50 | /// Print all data stored in the UserDefaults. 51 | static func printData() 52 | { 53 | print(UserDefaults.standard.dictionaryRepresentation()) 54 | } 55 | 56 | /// Load the contents of a txt file from a specified directory, like downloadsDirectory. 57 | /// 58 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 59 | static func loadFileContent(from: FileManager.SearchPathDirectory, name: String) -> String 60 | { 61 | let dir = FileManager.default.urls(for: from, in: .userDomainMask).first! 62 | let path = dir.appendingPathComponent(name) 63 | let text = try? String(contentsOf: path, encoding: String.Encoding.utf8) 64 | return text ?? "" 65 | } 66 | 67 | /// Save the contents of a String to a txt file in a specified directory, like 68 | /// downloadsDirectory. 69 | /// 70 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 71 | static func saveTxtFile(content: String, to: FileManager.SearchPathDirectory, name: String) 72 | { 73 | do 74 | { 75 | let dir = FileManager.default.urls(for: to, in: .userDomainMask).first! 76 | try content.write( 77 | to: dir.appendingPathComponent(name), 78 | atomically: false, 79 | encoding: String.Encoding.utf8 80 | ) 81 | } 82 | catch 83 | { 84 | print("Couldn't write to \(name) in \(to)") 85 | } 86 | } 87 | 88 | /// Save the contents of a String to a txt file in a specified directory, like 89 | /// downloadsDirectory. 90 | /// 91 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 92 | static func appendToTxtFile(content: String, to: FileManager.SearchPathDirectory, name: String) 93 | { 94 | let dir = FileManager.default.urls(for: to, in: .userDomainMask).first! 95 | let path = dir.appendingPathComponent(name) 96 | 97 | if FileManager.default.fileExists(atPath: path.path) { 98 | if let fileHandle = try? FileHandle(forUpdating: path) { 99 | fileHandle.seekToEndOfFile() 100 | fileHandle.write(content.data(using: .utf8, allowLossyConversion: false)!) 101 | fileHandle.closeFile() 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/BigNumber.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/BigNumber-iOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Tools/MG Benchmark Tools.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Benchmark Tools.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 03.04.2015. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | #if os(Linux) 11 | import Glibc 12 | import CBSD 13 | 14 | private func mach_absolute_time() -> UInt64 { 15 | var tv = timeval(); 16 | guard gettimeofday(&tv, nil) != -1 else { return 0 } 17 | 18 | let t = UInt64(tv.tv_usec) + UInt64(tv.tv_sec) * 1000000 19 | return t; 20 | } 21 | 22 | private struct mach_timebase_info_data_t { 23 | var numer: Int = 1000 24 | var denom: Int = 1 25 | } 26 | 27 | private func mach_timebase_info(_: inout mach_timebase_info_data_t) {} 28 | #endif 29 | 30 | /// Returns the time in nanoseconds it took to execute the call. 31 | private func durationNS(_ call: () -> ()) -> Int 32 | { 33 | var start = UInt64() 34 | var end = UInt64() 35 | 36 | start = mach_absolute_time() 37 | call() 38 | end = mach_absolute_time() 39 | 40 | var timeBaseInfo = mach_timebase_info_data_t() 41 | mach_timebase_info(&timeBaseInfo) 42 | 43 | return Int(end - start) * Int(timeBaseInfo.numer) / Int(timeBaseInfo.denom) 44 | } 45 | 46 | private func adjustPrecision(_ ns: Int, toPrecision: String) -> Int 47 | { 48 | switch toPrecision 49 | { 50 | case "ns": // nanoseconds 51 | return ns 52 | case "us": // microseconds 53 | return ns / 1_000 54 | case "ms": // milliseconds 55 | return ns / 1_000_000 56 | default: // seconds 57 | return ns / 1_000_000_000 58 | } 59 | } 60 | 61 | /** 62 | Measure execution time of trailing closure. 63 | 64 | - Parameter precision: Precision of measurement. Possible 65 | values: 66 | - "ns": nanoseconds 67 | - "us": microseconds 68 | - "ms" or omitted parameter: milliseconds 69 | - "s" or invalid input: seconds 70 | */ 71 | public func benchmark(_ precision: String = "ms", _ call: () -> ()) -> Int 72 | { 73 | // empty call duration to subtract 74 | let emptyCallElapsedNS = durationNS({}) 75 | let elapsedNS = durationNS(call) 76 | 77 | let elapsedCorrected = elapsedNS >= emptyCallElapsedNS 78 | ? elapsedNS - emptyCallElapsedNS 79 | : 0 80 | 81 | return adjustPrecision(elapsedCorrected, toPrecision: precision) 82 | } 83 | 84 | /** 85 | Measure execution time of trailing closure, and print result 86 | with description into the console. 87 | 88 | - Parameter precision: Precision of measurement. Possible 89 | values: 90 | - "ns": nanoseconds 91 | - "us": microseconds 92 | - "ms" or omitted parameter: milliseconds 93 | - "s" or invalid input: seconds 94 | 95 | - Parameter title: Description of benchmark. 96 | */ 97 | public func benchmarkAndPrint(_ precision: String = "ms", title: String, _ call: () -> ()) 98 | { 99 | print("=> \(title): \(benchmark(precision, call))\(precision)") 100 | } 101 | 102 | 103 | /** 104 | Measure the average execution time of trailing closure. 105 | 106 | - Parameter precision: Precision of measurement. Possible 107 | values: 108 | - "ns": nanoseconds 109 | - "us": microseconds 110 | - "ms" or omitted parameter: milliseconds 111 | - "s" or invalid input: seconds 112 | 113 | - Parameter title: Description of benchmark. 114 | 115 | - Parameter times: Amount of executions. 116 | Default when parameter is omitted: 100. 117 | 118 | - Returns: Minimum, Average and Maximum execution time of 119 | benchmarks as 3-tuple. 120 | */ 121 | public func benchmarkAvg( 122 | _ precision: String = "ms", 123 | times: Int = 10, 124 | _ call: () -> ()) 125 | -> (min: Int, avg: Int, max: Int) 126 | { 127 | let emptyCallsNS = durationNS({ 128 | for _ in 0.. max { max = duration } 142 | 143 | elapsedNSCombined += duration 144 | } 145 | 146 | let elapsedCorrected = elapsedNSCombined >= emptyCallsNS 147 | ? elapsedNSCombined - emptyCallsNS 148 | : 0 149 | 150 | return ( 151 | adjustPrecision(min, toPrecision: precision), 152 | adjustPrecision(elapsedCorrected / times, toPrecision: precision), 153 | adjustPrecision(max, toPrecision: precision) 154 | ) 155 | } 156 | 157 | public func benchmarkAvgPrint( 158 | _ precision: String = "ms", 159 | title: String, 160 | _ times: Int = 10, 161 | _ call: () -> ()) 162 | { 163 | let (min, avg, max) = benchmarkAvg(precision, times: times, call) 164 | 165 | let avgDur = "\(avg)" + precision + " average, " 166 | let minDur = "\(min)" + precision + " min, " 167 | let maxDur = "\(max)" + precision + " max" 168 | 169 | print("=> \(title): \(times) times, " + avgDur + minDur + maxDur) 170 | } 171 | -------------------------------------------------------------------------------- /Tools/MG SuperSwift.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * SuperSwift.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * SuperSwift is a file that aims to improve the swift programming language. It 6 | * adds missing functionality and convenient syntax to make the language more 7 | * versatile. 8 | * ———————————————————————————————————————————————————————————————————————————— 9 | * Created by Marcel Kröker on 18.02.2017. 10 | * Copyright © 2017 Marcel Kröker. All rights reserved. 11 | */ 12 | 13 | import Foundation 14 | 15 | // 16 | //// 17 | ////// 18 | //MARK: - Snippets 19 | ////// 20 | //// 21 | // 22 | 23 | /* 24 | Some snippets are essential to use SuperSwift. It defines some operators that are not 25 | typeable (or too hard to find) on a normal keyboard, thus it is recommended to use snippets 26 | in your IDE or xcode to have easy access to those operators. 27 | */ 28 | 29 | // The cartesian product 30 | // Shortcut: $cp 31 | // Operator: >< 32 | 33 | // The dot product, or scalar product 34 | // Shortcut: $dot 35 | // Operator: • 36 | 37 | // The element operator (same functionality as X.contains(y)) 38 | // Shortcut: $in 39 | // Operator: ∈ 40 | 41 | // The not element operator (same functionality as !X.contains(y)) 42 | // Shortcut: $notin 43 | // Operator: ∉ 44 | 45 | // 46 | //// 47 | ////// 48 | //MARK: - Overview 49 | ////// 50 | //// 51 | // 52 | 53 | /* 54 | This is an overview of all functionality of SuperSwift. 55 | */ 56 | 57 | 58 | 59 | 60 | // 61 | //// 62 | ////// 63 | //MARK: - Extensions 64 | ////// 65 | //// 66 | // 67 | 68 | public extension String 69 | { 70 | /// Returns character at index i as String. 71 | subscript(i: Int) -> String 72 | { 73 | return String(self[index(startIndex, offsetBy: i)]) 74 | } 75 | 76 | /// Returns characters in range as string. 77 | subscript(r: Range) -> String 78 | { 79 | let start = index(startIndex, offsetBy: r.lowerBound) 80 | let end = index(start, offsetBy: r.upperBound - r.lowerBound) 81 | 82 | return String(self[start..) 87 | { 88 | let start = self.index(self.startIndex, offsetBy: bounds.lowerBound) 89 | let end = self.index(self.startIndex, offsetBy: bounds.upperBound) 90 | self.removeSubrange(start...end) 91 | } 92 | 93 | // Make this function work with normal ranges. 94 | mutating func removeSubrange(_ bounds: CountableRange) 95 | { 96 | let start = self.index(self.startIndex, offsetBy: bounds.lowerBound) 97 | let end = self.index(self.startIndex, offsetBy: bounds.upperBound) 98 | self.removeSubrange(start..< : CartesianProductPrecedence 117 | 118 | /** 119 | Calculate the cartesian product of two sequences. With a left precedence you can iterate 120 | over the product: 121 | 122 | // Will print all numbers from 0000 to 9999 123 | for (((i, j), k), l) in 0...9 >< 0...9 >< 0...9 >< 0...9 124 | { 125 | print("\(i)\(j)\(k)\(l)") 126 | } 127 | 128 | 129 | - Parameter lhs: An array. 130 | - Parameter rhs: An array. 131 | - returns: [(l, r)] where l ∈ lhs and r ∈ rhs. 132 | */ 133 | func ><(lhs: [T1], rhs: [T2]) -> [(T1, T2)] 134 | { 135 | var res = [(T1, T2)]() 136 | 137 | for l in lhs 138 | { 139 | for r in rhs 140 | { 141 | res.append((l, r)) 142 | } 143 | } 144 | 145 | return res 146 | } 147 | 148 | func ><(lhs: CountableRange, rhs: CountableRange) -> [(Int, Int)] 149 | { 150 | return lhs.map{$0} >< rhs.map{$0} 151 | } 152 | 153 | func ><(lhs: CountableRange, rhs: CountableClosedRange) -> [(Int, Int)] 154 | { 155 | return lhs.map{$0} >< rhs.map{$0} 156 | } 157 | 158 | func ><(lhs: CountableClosedRange, rhs: CountableRange) -> [(Int, Int)] 159 | { 160 | return lhs.map{$0} >< rhs.map{$0} 161 | } 162 | 163 | func ><(lhs: CountableClosedRange, rhs: CountableClosedRange) -> [(Int, Int)] 164 | { 165 | return lhs.map{$0} >< rhs.map{$0} 166 | } 167 | 168 | func ><(lhs: [T], rhs: CountableRange) -> [(T, Int)] 169 | { 170 | return lhs >< rhs.map{$0} 171 | } 172 | 173 | func ><(lhs: [T], rhs: CountableClosedRange) -> [(T, Int)] 174 | { 175 | return lhs >< rhs.map{$0} 176 | } 177 | 178 | 179 | // Better syntax for contains. Works for sets and arrays 180 | 181 | infix operator ∈ 182 | 183 | func ∈(lhs: T, rhs: Set) -> Bool 184 | { 185 | return rhs.contains(lhs) 186 | } 187 | 188 | func ∈(lhs: T, rhs: Array) -> Bool 189 | { 190 | return rhs.contains(lhs) 191 | } 192 | 193 | infix operator ∉ 194 | 195 | func ∉(lhs: T, rhs: Array) -> Bool 196 | { 197 | return !rhs.contains(lhs) 198 | } 199 | 200 | func ∉(lhs: T, rhs: Set) -> Bool 201 | { 202 | return !rhs.contains(lhs) 203 | } 204 | -------------------------------------------------------------------------------- /Resources/longNumbers.json: -------------------------------------------------------------------------------- 1 | { 2 | "gcdTest1": "43875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583753489275632965239465894326503252306527465108761576016654310654156135610860276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694732645626564387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375348927563296523946589432650325230652746510876157601665431065415613561086027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369473264562656", 3 | "gcdTest2": "4387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369432087620650236402340623464743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694745624625443875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694320876206502364023406234647438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947456246254" 4 | } 5 | -------------------------------------------------------------------------------- /Tests/BIntTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BInt.swift 3 | // BigNumberTests 4 | // 5 | // Created by Zachary Gorak on 3/2/18. 6 | // Copyright © 2018 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class BIntTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testRadixInitializerAndGetter() 25 | { 26 | let chars: [Character] = [ 27 | "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", 28 | "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", 29 | "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", 30 | "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" 31 | ] 32 | 33 | #if !SWIFT_PACKAGE 34 | // Randomly choose two bases and a number length, as well as a sign (+ or -) 35 | for _ in 0..<100 36 | { 37 | let fromBase = math.random(2...62) 38 | let toBase = math.random(2...62) 39 | let numLength = math.random(1...100) 40 | let sign = math.random(0...1) == 1 ? "-" : "" 41 | 42 | // First digit should not be a 0. 43 | var num = sign + String(chars[math.random(1.. 255.0) 75 | XCTAssert(BInt("f",radix:16)! < 255.0) 76 | XCTAssert(BInt("0",radix:16)! <= 1.0) 77 | XCTAssert(BInt("f", radix: 16)! >= 1.0) 78 | XCTAssert(BInt("rfff",radix:16) == nil) 79 | 80 | XCTAssert(BInt("ffff",radix:16) == 65535) 81 | XCTAssert(BInt("rfff",radix:16) == nil) 82 | XCTAssert(BInt("ff",radix:10) == nil) 83 | XCTAssert(BInt("255",radix:6) == 107) 84 | XCTAssert(BInt("999",radix:10) == 999) 85 | XCTAssert(BInt("ff",radix:16) == 255.0) 86 | XCTAssert(BInt("ff",radix:16) != 100.0) 87 | XCTAssert(BInt("ffff",radix:16)! > 255.0) 88 | XCTAssert(BInt("f",radix:16)! < 255.0) 89 | XCTAssert(BInt("0",radix:16)! <= 1.0) 90 | XCTAssert(BInt("f",radix:16)! >= 1.0) 91 | XCTAssert(BInt("44",radix:5) == 24) 92 | XCTAssert(BInt("44",radix:5) != 100.0) 93 | XCTAssert(BInt("321",radix:5)! == 86) 94 | XCTAssert(BInt("3",radix:5)! < 255.0) 95 | XCTAssert(BInt("0",radix:5)! <= 1.0) 96 | XCTAssert(BInt("4",radix:5)! >= 1.0) 97 | XCTAssert(BInt("923492349",radix:32)! == 9967689075849) 98 | } 99 | 100 | func testPerformanceStringInit() { 101 | self.measure { 102 | for _ in (0...15000) { 103 | let _ = BInt(String(arc4random())) 104 | } 105 | } 106 | } 107 | 108 | func testPerformanceStringRadixInit() { 109 | self.measure { 110 | for _ in (0...15000) { 111 | let _ = BInt(String(arc4random()), radix: 10) 112 | } 113 | } 114 | } 115 | 116 | /** An issue was reported where a hex string was not being converted to a decimal. This test case checks that. */ 117 | func testIssue58() throws { 118 | // 190000000000000000000 119 | let x = try XCTUnwrap(BInt("0x00000000000000000000000000000000000000000000000a4cc799563c380000", radix: 16)) 120 | let y = try XCTUnwrap(BInt("0x00000000000000000000000000000000000000000000000a4cc799563c380000", radix: 16)) 121 | XCTAssertEqual(x, y) 122 | for radix in 2...16 { 123 | XCTAssertEqual(x.asString(radix: radix), y.asString(radix: radix)) 124 | } 125 | XCTAssertNotEqual(x, 0) 126 | XCTAssertGreaterThan(x, BInt(Int32.max)) 127 | XCTAssertEqual(x, BInt("190000000000000000000")) 128 | } 129 | 130 | func testIssue67() throws { 131 | let x = try XCTUnwrap(BInt("0b1310c5a2c30000", radix: 16)) 132 | XCTAssertEqual(x, BInt("0x0b1310c5a2c30000", radix: 16)) 133 | 134 | let y = try XCTUnwrap(BInt("0b", radix: 16)) 135 | XCTAssertEqual(y, 11) 136 | XCTAssertEqual(y, BInt("0xb", radix: 16)) 137 | XCTAssertEqual(y, BInt("0x0b", radix: 16)) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /docs/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /BigNumber.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint BigNumber.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "BigNumber" 19 | s.version = "2.2.0" 20 | s.summary = "A lightweight, high performance bignum library for Swift!" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = <<-DESC 28 | A lightweight, high performance bignum library for Swift for both intergers and doubles! 29 | DESC 30 | 31 | s.homepage = "https://github.com/mkrd/Swift-Big-Integer" 32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 33 | 34 | 35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 36 | # 37 | # Licensing your code is important. See http://choosealicense.com for more info. 38 | # CocoaPods will detect a license file if there is a named LICENSE* 39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 40 | # 41 | 42 | #s.license = "MIT (example)" 43 | s.license = { :type => "MIT", :file => "LICENSE" } 44 | 45 | 46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 47 | # 48 | # Specify the authors of the library, with email addresses. Email addresses 49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 50 | # accepts just a name if you'd rather not provide an email address. 51 | # 52 | # Specify a social_media_url where others can refer to, for example a twitter 53 | # profile URL. 54 | # 55 | 56 | s.author = "mkrd" 57 | # Or just: s.author = "twodayslate" 58 | # s.authors = { "twodayslate" => "zac@gorak.us" } 59 | # s.social_media_url = "http://twitter.com/twodayslate" 60 | 61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 62 | # 63 | # If this Pod runs only on iOS or OS X, then specify the platform and 64 | # the deployment target. You can optionally include the target after the platform. 65 | # 66 | 67 | # s.platform = :ios 68 | # s.platform = :ios, "5.0" 69 | 70 | # When using multiple platforms 71 | s.ios.deployment_target = "8.0" 72 | s.osx.deployment_target = "10.9" 73 | s.watchos.deployment_target = "2.0" 74 | s.tvos.deployment_target = "9.0" 75 | 76 | 77 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 78 | # 79 | # Specify the location from where the source should be retrieved. 80 | # Supports git, hg, bzr, svn and HTTP. 81 | # 82 | 83 | s.source = { :git => "https://github.com/mkrd/Swift-Big-Integer.git", :tag => "v#{s.version}" } 84 | 85 | 86 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 87 | # 88 | # CocoaPods is smart about how it includes source code. For source files 89 | # giving a folder will include any swift, h, m, mm, c & cpp files. 90 | # For header files it will include any header in the folder. 91 | # Not including the public_header_files will make all headers public. 92 | # 93 | s.source_files = "Sources/*.swift" 94 | 95 | #s.source_files = "Classes", "Classes/**/*.{h,m}" 96 | #s.exclude_files = "Classes/Exclude" 97 | 98 | # s.public_header_files = "Classes/**/*.h" 99 | 100 | 101 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 102 | # 103 | # A list of resources included with the Pod. These are copied into the 104 | # target bundle with a build phase script. Anything else will be cleaned. 105 | # You can preserve files from being cleaned, please don't preserve 106 | # non-essential files like tests, examples and documentation. 107 | # 108 | 109 | # s.resource = "icon.png" 110 | # s.resources = "Resources/*.png" 111 | 112 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 113 | 114 | 115 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 116 | # 117 | # Link your library with frameworks, or libraries. Libraries do not include 118 | # the lib prefix of their name. 119 | # 120 | 121 | # s.framework = "SomeFramework" 122 | # s.frameworks = "SomeFramework", "AnotherFramework" 123 | 124 | # s.library = "iconv" 125 | # s.libraries = "iconv", "xml2" 126 | 127 | 128 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 129 | # 130 | # If your library depends on compiler flags you can set them in the xcconfig hash 131 | # where they will only apply to your library. If you depend on other Podspecs 132 | # you can include multiple dependencies to ensure it works. 133 | 134 | # s.requires_arc = true 135 | 136 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 137 | # s.dependency "JSONKit", "~> 1.4" 138 | 139 | end 140 | -------------------------------------------------------------------------------- /Benchmarks/Benchmarks.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * Benchmarks.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 05.09.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | public class Benchmarks 12 | { 13 | static func Matrix1() 14 | { 15 | let A = Matrix( 16 | [[2,5,-2], 17 | [3,5,6], 18 | [-55,4,3]] 19 | ) 20 | 21 | let G12 = Matrix([ 22 | [0.8, -0.6, 0.0], 23 | [0.6, 0.8, 0.0], 24 | [0.0, 0.0, 1.0] 25 | ]) 26 | 27 | 28 | let al = Matrix([4, -3, 1]) 29 | 30 | print(G12 * al) 31 | 32 | let (L, R, P, D) = LRDecompPivEquil(A) 33 | 34 | print(solveGauss(A, [2.0, -4.0, 15.0])) 35 | print(solveLR(A, [2.0, -4.0, 15.0])) 36 | print(solveLRPD(A, [2.0, -4.0, 15.0])) 37 | 38 | print("P L R") 39 | print(P) 40 | print(L) 41 | print(R) 42 | 43 | print("LR == PDA") 44 | print(L * R) 45 | print(P * D * A) 46 | 47 | 48 | benchmarkAndPrint(title: "Matix ^ 100") 49 | { 50 | var R = A 51 | for _ in 0...100 52 | { 53 | R = R * A 54 | } 55 | } 56 | } 57 | 58 | static func BDoubleConverging() 59 | { 60 | benchmarkAndPrint(title: "BDouble converging to 2") 61 | { 62 | // BDouble converging to 2 Debug Mode 63 | // 06.02.16: 3351ms 64 | 65 | var res: BDouble = 0 66 | var den: BInt = 1 67 | 68 | for _ in 0..<1000 69 | { 70 | res = res + BDouble(BInt(1), over: den) 71 | den *= 2 72 | } 73 | } 74 | } 75 | 76 | static func factorial() 77 | { 78 | let n = 25_000 79 | 80 | benchmarkAndPrint(title: "Factorial of 25000") 81 | { 82 | // Fkt 1000 Debug Mode 83 | // 27.01.16: 2548ms 84 | // 30.01.16: 1707ms 85 | // 01.02.16: 398ms 86 | 87 | // Fkt 2000 Debug Mode 88 | // 01.02.16: 2452ms 89 | // 04.02.16: 2708ms 90 | // 06.02.16: 328ms 91 | 92 | // Factorial 4000 Debug Mode 93 | // 06.02.16: 2669ms 94 | // 10.02.16: 571ms 95 | // 28.02.16: 550ms 96 | // 01.03.16: 56ms 97 | 98 | // Factorial 25000 Debug Mode 99 | // 01.03.16: 2871ms 100 | // 07.03.16: 2221ms 101 | // 16.08.16: 1759ms 102 | // 20.08.16: 1367ms 103 | // 23.08.19: 1075ms 104 | _ = BInt(n).factorial() 105 | } 106 | } 107 | 108 | static func exponentiation() 109 | { 110 | let n = 10 111 | let pow = 120_000 112 | 113 | benchmarkAndPrint(title: "10^120_000") 114 | { 115 | // 10^14000 Debug Mode 116 | // 06.02.16: 2668ms 117 | // 10.02.16: 372ms 118 | // 20.02.16: 320ms 119 | // 28.02.16: 209ms 120 | // 01.03.16: 39ms 121 | 122 | // 10^120_000 Debug Mode 123 | // 01.03.16: 2417ms 124 | // 07.03.16: 1626ms 125 | // 16.08.16: 1154ms 126 | // 20.08.16: 922ms 127 | // 23.08.19: 710ms 128 | 129 | _ = BInt(n) ** pow 130 | } 131 | } 132 | 133 | static func fibonacci() 134 | { 135 | let n = 100_000 136 | 137 | benchmarkAndPrint(title: "Fib \(n)") 138 | { 139 | // Fib 35.000 Debug Mode 140 | // 27.01.16: 2488ms 141 | // 30.01.16: 1458ms 142 | // 01.02.16: 357ms 143 | 144 | // Fib 100.000 Debug Mode 145 | // 01.02.16: 2733ms 146 | // 04.02.16: 2949ms 147 | // 10.02.16: 1919ms 148 | // 28.02.16: 1786ms 149 | // 07.03.16: 1716ms 150 | // 23.08.19: 1124ms 151 | 152 | _ = BIntMath.fib(n) 153 | } 154 | } 155 | 156 | static func mersennes() 157 | { 158 | let n = 256 159 | 160 | benchmarkAndPrint(title: "\nMersennes to 2^\(n)") 161 | { 162 | // Mersenne to exp 256 Debug Mode 163 | // 02.10.16: 1814ms 164 | 165 | for i in 1...n 166 | { 167 | if math.isPrime(i) && BIntMath.isMersenne(i) 168 | { 169 | print(i, terminator: ",") 170 | } 171 | } 172 | 173 | } 174 | } 175 | 176 | static func BIntToString() 177 | { 178 | let factorialBase = 15_000 179 | let n = BInt(factorialBase).factorial() 180 | benchmarkAndPrint(title: "Get \(factorialBase)! as String") 181 | { 182 | // Get 300! (615 decimal digits) as String Debug Mode 183 | // 30.01.16: 2635ms 184 | // 01.02.16: 3723ms 185 | // 04.02.16: 2492m 186 | // 06.02.16: 2326ms 187 | // 07.02.16: 53ms 188 | 189 | // Get 1000! (2568 decimal digits) as String Debug Mode 190 | // 07.02.16: 2386ms 191 | // 10.02.16: 343ms 192 | // 20.02.16: 338ms 193 | // 22.02.16: 159ms 194 | 195 | // Get 3000! (9131 decimal digits) as String Debug Mode 196 | // 22.02.16: 2061ms 197 | // 28.02.16: 1891ms 198 | // 01.03.16: 343ms 199 | 200 | // Get 7500! (25809 decimal digits) as String Debug Mode 201 | // 01.03.16: 2558ms 202 | // 07.03.16: 1604ms 203 | // 07.03.16: 1562ms 204 | // 16.08.16: 455ms 205 | 206 | // Get 15000! (56130 decimal digits) as String Debug Mode 207 | // 07.09.17: 2701ms 208 | 209 | _ = n.description 210 | } 211 | } 212 | 213 | static func StringToBInt() 214 | { 215 | let factorialBase = 16_000 216 | let asStr = BInt(factorialBase).factorial().description 217 | var res: BInt = 0 218 | 219 | benchmarkAndPrint(title: "BInt from String, \(asStr.count) digits (\(factorialBase)!)") 220 | { 221 | // BInt from String, 3026 digits (1151!) Debug Mode 222 | // 07.02.16: 2780ms 223 | // 10.02.16: 1135ms 224 | // 28.02.16: 1078ms 225 | // 01.03.16: 430ms 226 | 227 | // BInt from String, 9131 digits (3000!) Debug Mode 228 | // 01.03.16: 3469ms 229 | // 07.03.16: 2305ms 230 | // 07.03.16: 1972ms 231 | // 26.06.16: 644ms 232 | 233 | // BInt from String, 20066 digits (6000!) Debug Mode 234 | // 26.06.16: 3040ms 235 | // 16.08.16: 2684ms 236 | // 20.08.16: 2338ms 237 | 238 | // BInt from String, 60320 digits (16000!) Debug Mode 239 | // 07.09.17: 2857ms 240 | // 26.04.18: 1081ms 241 | 242 | res = BInt(asStr)! 243 | } 244 | 245 | assert(asStr == res.description) 246 | } 247 | 248 | static func permutationsAndCombinations() 249 | { 250 | benchmarkAndPrint(title: "Perm and Comb") 251 | { 252 | // Perm and Comb (2000, 1000) Debug Mode 253 | // 04.02.16: 2561ms 254 | // 06.02.16: 2098ms 255 | // 07.02.16: 1083ms 256 | // 10.02.16: 350ms 257 | // 28.02.16: 337ms 258 | // 01.03.16: 138ms 259 | 260 | // Perm and Comb (8000, 4000) Debug Mode 261 | // 07.03.16: 905ms 262 | // 07.03.16: 483ms 263 | 264 | _ = BIntMath.permutations(8000, 4000) 265 | _ = BIntMath.combinations(8000, 4000) 266 | } 267 | } 268 | 269 | static func multiplicationBalanced() 270 | { 271 | let b1 = BIntMath.randomBInt(bits: 270_000) 272 | let b2 = BIntMath.randomBInt(bits: 270_000) 273 | 274 | benchmarkAndPrint(title: "Multiply two random BInts with size of 270_000 and 270_000 bits") 275 | { 276 | // Multiply two random BInts with size of 270_000 and 270_000 bits 277 | // 26.04.18: 2427ms 278 | 279 | _ = b1 * b2 280 | } 281 | } 282 | 283 | static func multiplicationUnbalanced() 284 | { 285 | let b1 = BIntMath.randomBInt(bits: 70_000_000) 286 | let b2 = BIntMath.randomBInt(bits: 1_000) 287 | 288 | benchmarkAndPrint(title: "Multiply two random BInts with size of 70_000_000 and 1_000 bits") 289 | { 290 | // Multiply two random BInts with size of 70_000_000 and 1_000 bits 291 | // 26.04.18: 2467ms 292 | 293 | _ = b1 * b2 294 | } 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /Carthage/Build/iOS/BigNumber.framework/Headers/BigNumber-Swift.h: -------------------------------------------------------------------------------- 1 | // Generated by Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) 2 | #pragma clang diagnostic push 3 | #pragma clang diagnostic ignored "-Wgcc-compat" 4 | 5 | #if !defined(__has_include) 6 | # define __has_include(x) 0 7 | #endif 8 | #if !defined(__has_attribute) 9 | # define __has_attribute(x) 0 10 | #endif 11 | #if !defined(__has_feature) 12 | # define __has_feature(x) 0 13 | #endif 14 | #if !defined(__has_warning) 15 | # define __has_warning(x) 0 16 | #endif 17 | 18 | #if __has_attribute(external_source_symbol) 19 | # define SWIFT_STRINGIFY(str) #str 20 | # define SWIFT_MODULE_NAMESPACE_PUSH(module_name) _Pragma(SWIFT_STRINGIFY(clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in=module_name, generated_declaration))), apply_to=any(function, enum, objc_interface, objc_category, objc_protocol)))) 21 | # define SWIFT_MODULE_NAMESPACE_POP _Pragma("clang attribute pop") 22 | #else 23 | # define SWIFT_MODULE_NAMESPACE_PUSH(module_name) 24 | # define SWIFT_MODULE_NAMESPACE_POP 25 | #endif 26 | 27 | #if __has_include() 28 | # include 29 | #endif 30 | 31 | #pragma clang diagnostic ignored "-Wauto-import" 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #if !defined(SWIFT_TYPEDEFS) 38 | # define SWIFT_TYPEDEFS 1 39 | # if __has_include() 40 | # include 41 | # elif !defined(__cplusplus) || __cplusplus < 201103L 42 | typedef uint_least16_t char16_t; 43 | typedef uint_least32_t char32_t; 44 | # endif 45 | typedef float swift_float2 __attribute__((__ext_vector_type__(2))); 46 | typedef float swift_float3 __attribute__((__ext_vector_type__(3))); 47 | typedef float swift_float4 __attribute__((__ext_vector_type__(4))); 48 | typedef double swift_double2 __attribute__((__ext_vector_type__(2))); 49 | typedef double swift_double3 __attribute__((__ext_vector_type__(3))); 50 | typedef double swift_double4 __attribute__((__ext_vector_type__(4))); 51 | typedef int swift_int2 __attribute__((__ext_vector_type__(2))); 52 | typedef int swift_int3 __attribute__((__ext_vector_type__(3))); 53 | typedef int swift_int4 __attribute__((__ext_vector_type__(4))); 54 | typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2))); 55 | typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3))); 56 | typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4))); 57 | #endif 58 | 59 | #if !defined(SWIFT_PASTE) 60 | # define SWIFT_PASTE_HELPER(x, y) x##y 61 | # define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) 62 | #endif 63 | #if !defined(SWIFT_METATYPE) 64 | # define SWIFT_METATYPE(X) Class 65 | #endif 66 | #if !defined(SWIFT_CLASS_PROPERTY) 67 | # if __has_feature(objc_class_property) 68 | # define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__ 69 | # else 70 | # define SWIFT_CLASS_PROPERTY(...) 71 | # endif 72 | #endif 73 | 74 | #if __has_attribute(objc_runtime_name) 75 | # define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) 76 | #else 77 | # define SWIFT_RUNTIME_NAME(X) 78 | #endif 79 | #if __has_attribute(swift_name) 80 | # define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) 81 | #else 82 | # define SWIFT_COMPILE_NAME(X) 83 | #endif 84 | #if __has_attribute(objc_method_family) 85 | # define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X))) 86 | #else 87 | # define SWIFT_METHOD_FAMILY(X) 88 | #endif 89 | #if __has_attribute(noescape) 90 | # define SWIFT_NOESCAPE __attribute__((noescape)) 91 | #else 92 | # define SWIFT_NOESCAPE 93 | #endif 94 | #if __has_attribute(warn_unused_result) 95 | # define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 96 | #else 97 | # define SWIFT_WARN_UNUSED_RESULT 98 | #endif 99 | #if __has_attribute(noreturn) 100 | # define SWIFT_NORETURN __attribute__((noreturn)) 101 | #else 102 | # define SWIFT_NORETURN 103 | #endif 104 | #if !defined(SWIFT_CLASS_EXTRA) 105 | # define SWIFT_CLASS_EXTRA 106 | #endif 107 | #if !defined(SWIFT_PROTOCOL_EXTRA) 108 | # define SWIFT_PROTOCOL_EXTRA 109 | #endif 110 | #if !defined(SWIFT_ENUM_EXTRA) 111 | # define SWIFT_ENUM_EXTRA 112 | #endif 113 | #if !defined(SWIFT_CLASS) 114 | # if __has_attribute(objc_subclassing_restricted) 115 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA 116 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 117 | # else 118 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 119 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 120 | # endif 121 | #endif 122 | 123 | #if !defined(SWIFT_PROTOCOL) 124 | # define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 125 | # define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 126 | #endif 127 | 128 | #if !defined(SWIFT_EXTENSION) 129 | # define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) 130 | #endif 131 | 132 | #if !defined(OBJC_DESIGNATED_INITIALIZER) 133 | # if __has_attribute(objc_designated_initializer) 134 | # define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) 135 | # else 136 | # define OBJC_DESIGNATED_INITIALIZER 137 | # endif 138 | #endif 139 | #if !defined(SWIFT_ENUM_ATTR) 140 | # if defined(__has_attribute) && __has_attribute(enum_extensibility) 141 | # define SWIFT_ENUM_ATTR __attribute__((enum_extensibility(open))) 142 | # else 143 | # define SWIFT_ENUM_ATTR 144 | # endif 145 | #endif 146 | #if !defined(SWIFT_ENUM) 147 | # define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type 148 | # if __has_feature(generalized_swift_name) 149 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type 150 | # else 151 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name) 152 | # endif 153 | #endif 154 | #if !defined(SWIFT_UNAVAILABLE) 155 | # define SWIFT_UNAVAILABLE __attribute__((unavailable)) 156 | #endif 157 | #if !defined(SWIFT_UNAVAILABLE_MSG) 158 | # define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg))) 159 | #endif 160 | #if !defined(SWIFT_AVAILABILITY) 161 | # define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__))) 162 | #endif 163 | #if !defined(SWIFT_DEPRECATED) 164 | # define SWIFT_DEPRECATED __attribute__((deprecated)) 165 | #endif 166 | #if !defined(SWIFT_DEPRECATED_MSG) 167 | # define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__))) 168 | #endif 169 | #if __has_feature(attribute_diagnose_if_objc) 170 | # define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning"))) 171 | #else 172 | # define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg) 173 | #endif 174 | #if __has_feature(modules) 175 | #endif 176 | 177 | #pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" 178 | #pragma clang diagnostic ignored "-Wduplicate-method-arg" 179 | #if __has_warning("-Wpragma-clang-attribute") 180 | # pragma clang diagnostic ignored "-Wpragma-clang-attribute" 181 | #endif 182 | #pragma clang diagnostic ignored "-Wunknown-pragmas" 183 | #pragma clang diagnostic ignored "-Wnullability" 184 | 185 | SWIFT_MODULE_NAMESPACE_PUSH("BigNumber") 186 | SWIFT_MODULE_NAMESPACE_POP 187 | #pragma clang diagnostic pop 188 | -------------------------------------------------------------------------------- /Carthage/Build/Mac/BigNumber.framework/Versions/A/Headers/BigNumber-Swift.h: -------------------------------------------------------------------------------- 1 | // Generated by Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) 2 | #pragma clang diagnostic push 3 | #pragma clang diagnostic ignored "-Wgcc-compat" 4 | 5 | #if !defined(__has_include) 6 | # define __has_include(x) 0 7 | #endif 8 | #if !defined(__has_attribute) 9 | # define __has_attribute(x) 0 10 | #endif 11 | #if !defined(__has_feature) 12 | # define __has_feature(x) 0 13 | #endif 14 | #if !defined(__has_warning) 15 | # define __has_warning(x) 0 16 | #endif 17 | 18 | #if __has_attribute(external_source_symbol) 19 | # define SWIFT_STRINGIFY(str) #str 20 | # define SWIFT_MODULE_NAMESPACE_PUSH(module_name) _Pragma(SWIFT_STRINGIFY(clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in=module_name, generated_declaration))), apply_to=any(function, enum, objc_interface, objc_category, objc_protocol)))) 21 | # define SWIFT_MODULE_NAMESPACE_POP _Pragma("clang attribute pop") 22 | #else 23 | # define SWIFT_MODULE_NAMESPACE_PUSH(module_name) 24 | # define SWIFT_MODULE_NAMESPACE_POP 25 | #endif 26 | 27 | #if __has_include() 28 | # include 29 | #endif 30 | 31 | #pragma clang diagnostic ignored "-Wauto-import" 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #if !defined(SWIFT_TYPEDEFS) 38 | # define SWIFT_TYPEDEFS 1 39 | # if __has_include() 40 | # include 41 | # elif !defined(__cplusplus) || __cplusplus < 201103L 42 | typedef uint_least16_t char16_t; 43 | typedef uint_least32_t char32_t; 44 | # endif 45 | typedef float swift_float2 __attribute__((__ext_vector_type__(2))); 46 | typedef float swift_float3 __attribute__((__ext_vector_type__(3))); 47 | typedef float swift_float4 __attribute__((__ext_vector_type__(4))); 48 | typedef double swift_double2 __attribute__((__ext_vector_type__(2))); 49 | typedef double swift_double3 __attribute__((__ext_vector_type__(3))); 50 | typedef double swift_double4 __attribute__((__ext_vector_type__(4))); 51 | typedef int swift_int2 __attribute__((__ext_vector_type__(2))); 52 | typedef int swift_int3 __attribute__((__ext_vector_type__(3))); 53 | typedef int swift_int4 __attribute__((__ext_vector_type__(4))); 54 | typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2))); 55 | typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3))); 56 | typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4))); 57 | #endif 58 | 59 | #if !defined(SWIFT_PASTE) 60 | # define SWIFT_PASTE_HELPER(x, y) x##y 61 | # define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) 62 | #endif 63 | #if !defined(SWIFT_METATYPE) 64 | # define SWIFT_METATYPE(X) Class 65 | #endif 66 | #if !defined(SWIFT_CLASS_PROPERTY) 67 | # if __has_feature(objc_class_property) 68 | # define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__ 69 | # else 70 | # define SWIFT_CLASS_PROPERTY(...) 71 | # endif 72 | #endif 73 | 74 | #if __has_attribute(objc_runtime_name) 75 | # define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) 76 | #else 77 | # define SWIFT_RUNTIME_NAME(X) 78 | #endif 79 | #if __has_attribute(swift_name) 80 | # define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) 81 | #else 82 | # define SWIFT_COMPILE_NAME(X) 83 | #endif 84 | #if __has_attribute(objc_method_family) 85 | # define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X))) 86 | #else 87 | # define SWIFT_METHOD_FAMILY(X) 88 | #endif 89 | #if __has_attribute(noescape) 90 | # define SWIFT_NOESCAPE __attribute__((noescape)) 91 | #else 92 | # define SWIFT_NOESCAPE 93 | #endif 94 | #if __has_attribute(warn_unused_result) 95 | # define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 96 | #else 97 | # define SWIFT_WARN_UNUSED_RESULT 98 | #endif 99 | #if __has_attribute(noreturn) 100 | # define SWIFT_NORETURN __attribute__((noreturn)) 101 | #else 102 | # define SWIFT_NORETURN 103 | #endif 104 | #if !defined(SWIFT_CLASS_EXTRA) 105 | # define SWIFT_CLASS_EXTRA 106 | #endif 107 | #if !defined(SWIFT_PROTOCOL_EXTRA) 108 | # define SWIFT_PROTOCOL_EXTRA 109 | #endif 110 | #if !defined(SWIFT_ENUM_EXTRA) 111 | # define SWIFT_ENUM_EXTRA 112 | #endif 113 | #if !defined(SWIFT_CLASS) 114 | # if __has_attribute(objc_subclassing_restricted) 115 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA 116 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 117 | # else 118 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 119 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 120 | # endif 121 | #endif 122 | 123 | #if !defined(SWIFT_PROTOCOL) 124 | # define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 125 | # define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 126 | #endif 127 | 128 | #if !defined(SWIFT_EXTENSION) 129 | # define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) 130 | #endif 131 | 132 | #if !defined(OBJC_DESIGNATED_INITIALIZER) 133 | # if __has_attribute(objc_designated_initializer) 134 | # define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) 135 | # else 136 | # define OBJC_DESIGNATED_INITIALIZER 137 | # endif 138 | #endif 139 | #if !defined(SWIFT_ENUM_ATTR) 140 | # if defined(__has_attribute) && __has_attribute(enum_extensibility) 141 | # define SWIFT_ENUM_ATTR __attribute__((enum_extensibility(open))) 142 | # else 143 | # define SWIFT_ENUM_ATTR 144 | # endif 145 | #endif 146 | #if !defined(SWIFT_ENUM) 147 | # define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type 148 | # if __has_feature(generalized_swift_name) 149 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type 150 | # else 151 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name) 152 | # endif 153 | #endif 154 | #if !defined(SWIFT_UNAVAILABLE) 155 | # define SWIFT_UNAVAILABLE __attribute__((unavailable)) 156 | #endif 157 | #if !defined(SWIFT_UNAVAILABLE_MSG) 158 | # define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg))) 159 | #endif 160 | #if !defined(SWIFT_AVAILABILITY) 161 | # define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__))) 162 | #endif 163 | #if !defined(SWIFT_DEPRECATED) 164 | # define SWIFT_DEPRECATED __attribute__((deprecated)) 165 | #endif 166 | #if !defined(SWIFT_DEPRECATED_MSG) 167 | # define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__))) 168 | #endif 169 | #if __has_feature(attribute_diagnose_if_objc) 170 | # define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning"))) 171 | #else 172 | # define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg) 173 | #endif 174 | #if __has_feature(modules) 175 | #endif 176 | 177 | #pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" 178 | #pragma clang diagnostic ignored "-Wduplicate-method-arg" 179 | #if __has_warning("-Wpragma-clang-attribute") 180 | # pragma clang diagnostic ignored "-Wpragma-clang-attribute" 181 | #endif 182 | #pragma clang diagnostic ignored "-Wunknown-pragmas" 183 | #pragma clang diagnostic ignored "-Wnullability" 184 | 185 | SWIFT_MODULE_NAMESPACE_PUSH("BigNumber") 186 | SWIFT_MODULE_NAMESPACE_POP 187 | #pragma clang diagnostic pop 188 | -------------------------------------------------------------------------------- /Tests/Test_Basic_Math.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_Basic_Math.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_Basic_Math: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | 23 | func test_Arithmetric_Operators_BInt() 24 | { 25 | // Ensure that BInt operators behave like swift operators. 26 | let iterations = 1_000 27 | // Get a appropriate maximum number magnitude 28 | let m = Int(sqrt(Double(iterations))) / 10 29 | 30 | let arithmetricInt: [(Int, Int ) -> Int ] = [(+), (-), (*), (/), (%)] 31 | let arithmetricBInt: [(BInt, BInt) -> BInt] = [(+), (-), (*), (/), (%)] 32 | 33 | #if !SWIFT_PACKAGE 34 | for (_, i_op) in (0..<(0.. 2 && y == 0) { continue } 38 | let resInt = (arithmetricInt[i_op])(x, y) 39 | let resBInt = (arithmetricBInt[i_op])(BInt(x), BInt(y)) 40 | XCTAssert(resInt.description == resBInt.description) 41 | } 42 | #endif 43 | } 44 | 45 | func test_Comparison_Operators_BInt() 46 | { 47 | // Ensure that BInt comparison operators behave like swift operators. 48 | let iterations = 1_000 49 | 50 | // Get a appropriate maximum number magnitude 51 | let m = Int(sqrt(Double(iterations))) / 10 52 | 53 | let compareInt: [(Int, Int) -> Bool] = [(<), (<=), (>), (>=), (==), (!=)] 54 | let compareBInt: [(BInt, BInt) -> Bool] = [(<), (<=), (>), (>=), (==), (!=)] 55 | 56 | #if !SWIFT_PACKAGE 57 | for (_, i_op) in (0..<(0.. UInt64] = [(<<), (>>)] 73 | let shiftBInt: [(BInt, Int) -> BInt ] = [(<<), (>>)] 74 | 75 | #if !SWIFT_PACKAGE 76 | for (_, i_op) in (0..<(0.. 2 | 3 | 4 | Int Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Int

134 |
135 |
136 |
@frozen
137 | extension Int: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(floatLiteral:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    public init(floatLiteral value: Double)
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swift-BigInt 2 | Swift-BigInt is a lightweight, and easy-to-use, arbitrary precision arithmetric library for Swift 5. 3 | 4 | It supports whole Numbers (BInt) and Fractions (BDouble) with most of the common math operators. Optimized mathematical functions like factorial or gcd are also implemented and are accessible through BIntMath. For more details, please continue reading. 5 | 6 | Some benchmarks are located in Benchmarks.swift, note that these are more than 10 times faster in the release mode, compared to the debug mode of Xcode. 7 | 8 | # Survey Time! 9 | 10 | [Survey Link](https://forms.gle/9ycR8eUEsCenvMUn7) 11 | 12 | We want to hear your opinion about Swift BigInt! If you have a few minutes, please help us with answering a few questions about how you use this project, and tell us your opinion about it. The survey is completely anonymous, and will be used to evaluate which features will be prioritized in the future. 13 | 14 | 15 | 16 | 17 | # Installation 18 | 19 | ## Drag and Drop 20 | One of the main goals of this library is to be lightweight and independent. 21 | 22 | Simply drag and drop `Swift-Big-Number-Core.swift` from the `sources` folder into your project! 23 | 24 | Yes, it's that easy :) 25 | 26 | 27 | ## Swift Package Manager 28 | 29 | You can use the [Swift Package Manager](https://swift.org/package-manager/) and specify the package dependency in your `Package.swift` file by adding this: 30 | ``` 31 | .Package(url: "https://github.com/mkrd/Swift-BigInt.git", branch: "master") 32 | ``` 33 | 34 | ``` 35 | import BigNumber 36 | ``` 37 | 38 | 39 | ## CocoaPods 40 | 41 | Put the following in your Podfile: 42 | ``` 43 | pod 'BigNumber', '~> 2.0', :git => 'https://github.com/mkrd/Swift-Big-Integer.git' 44 | ``` 45 | 46 | 47 | # Compatibility 48 | It is recommended to use Xcode 9+ and Swift 4+. Issues have been reported with older versions, so you might want to use an older version of this library if you can't update. 49 | 50 | 51 | # Getting Started 52 | Here is a small example, to showcase some functionalities of this library. If you want to learn more, please continue reading the Usage section below. 53 | 54 | ```swift 55 | let a = BInt(12) 56 | let b = BInt("-10000000000000000000000000000000000000000000000000000000000000000")! 57 | 58 | print(b) 59 | >>> -10000000000000000000000000000000000000000000000000000000000000000 60 | 61 | print(-a * b) 62 | >>> 120000000000000000000000000000000000000000000000000000000000000000 63 | 64 | print(BInt(200).factorial()) 65 | >>> 788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000 66 | ``` 67 | 68 | # Usage 69 | 70 | ## BInt 71 | 72 | ### Initialization 73 | You initialize BInt with `Int`, `UInt`, and `String`. If you use a `String`, the initialized `BInt` will be an optional type, which will be empty if the `String` does not contain an valid number. 74 | 75 | ``` 76 | BInt(Int) 77 | BInt(UInt) 78 | BInt(String)? 79 | BInt(String, radix: Int)? 80 | ``` 81 | 82 | ### Examples 83 | ```swift 84 | let a = BInt(12) 85 | print(a) 86 | >>> 12 87 | 88 | 89 | let b = BInt("-234324176583764598326758236587632649181349105368042856028465298620328782652623") 90 | print(b!) 91 | >>> -234324176583764598326758236587632649181349105368042856028465298620328782652623 92 | 93 | 94 | let invalid = BInt("I'm not a number") 95 | if let c = invalid { 96 | print(c) 97 | } else { 98 | print("Not a valid number!") 99 | } 100 | >>> Not a valid number! 101 | 102 | 103 | let d = BInt("fff", radix: 16) 104 | print(d) 105 | >>> 4095 106 | ``` 107 | 108 | ### BInt offers these struct methods 109 | ```swift 110 | let big = BInt("-143141341")! 111 | 112 | big.description // Returns "-143141341" 113 | => print(big) // prints "-143141341" 114 | 115 | big.toInt() // returns -143141341 (only works when Int.min <= big <= Int.max) 116 | 117 | big.isPositive() // Returns false 118 | big.isNegative() // Returns true 119 | big.isZero() // Returns false 120 | 121 | big.negate() // Returns noting, but negates the BInt (mutating func) 122 | 123 | big.rawData() // Returns internal structure 124 | ``` 125 | 126 | ## The following Operators work with BInt 127 | ```swift 128 | // Operating on Int and BInt result in a typecast to BInt 129 | 130 | // Addition 131 | BIntOrInt + BIntOrInt // Returns BInt 132 | BIntOrInt += BIntOrInt 133 | 134 | //Subtraction 135 | BIntOrInt - BIntOrInt // Returns BInt 136 | BIntOrInt -= BIntOrInt 137 | 138 | // Multiplication 139 | BIntOrInt * BIntOrInt // Returns BInt 140 | BIntOrInt *= BIntOrInt 141 | 142 | // Exponentiation 143 | BInt ** Int // Retuns BInt to the power of Int 144 | 145 | // Modulo 146 | BIntOrInt % BIntOrInt // Returns BInt 147 | BInt %= BInt 148 | 149 | // Division 150 | BInt / BInt // Returns BInt 151 | BInt /= BInt 152 | 153 | 154 | // Comparing 155 | BInt == BInt 156 | BInt != BInt 157 | BInt < BInt 158 | BInt <= BInt 159 | BInt > BInt 160 | BInt >= BInt 161 | ``` 162 | 163 | ### Implemented BInt math functions 164 | ```swift 165 | fact(Int) // Returns factorial as BInt 166 | 167 | gcd(BInt, BInt) // Returns greatest common divisor as BInt 168 | 169 | lcm(BInt, BInt) // Returns lowest common multiple as BInt 170 | 171 | permutations(BInt, BInt) // Returns BInt 172 | 173 | combinations(BInt, BInt) // Returns BInt 174 | ``` 175 | 176 | ### Compatibility with Bignum 177 | 178 | `BInt` has a typealias to `Bignum` that is largely drop-in compatible with the OpenSSL-based [Swift big number library](https://github.com/Bouke/Bignum). The following properties and operations are available on `BInt`/`Bignum`: 179 | 180 | ```swift 181 | public var data: Data /// Representation as big-endian Data 182 | public var dec: String /// Decimal string representation 183 | public var hex: String /// Hexadecimal string representation 184 | 185 | public init(hex: String) /// Initialise a new BInt from a hexadecimal string 186 | public init(_ n: UInt64) /// Initialise from an unsigned, 64 bit integer 187 | public init(data: Data) /// Initialise from big-endian Data 188 | 189 | /// Combined exponentiation/modulo algorithm 190 | /// 191 | /// - Parameters: 192 | /// - b: base 193 | /// - p: power 194 | /// - m: modulus 195 | /// - Returns: pow(b, p) % m 196 | public func mod_exp(_ b: BInt, _ p: BInt, _ m: BInt) -> BInt 197 | 198 | /// Non-negative modulo operation 199 | /// 200 | /// - Parameters: 201 | /// - a: left hand side of the module operation 202 | /// - m: modulus 203 | /// - Returns: r := a % b such that 0 <= r < abs(m) 204 | public func nnmod(_ a: BInt, _ m: BInt) -> BInt 205 | ``` 206 | 207 | ## BDouble 208 | 209 | ### BDouble allows these constructors 210 | ```swift 211 | BDouble(Int) 212 | BDouble(Double) 213 | BDouble(String)? 214 | BDouble(Int, over: Int) 215 | BDouble(String, over: String)? 216 | BDouble(String, radix: Int)? 217 | ``` 218 | 219 | ### Examples 220 | ```swift 221 | let integer = BDouble(221) 222 | let double = BDouble(1.192) 223 | let fraction = BDouble(3, over: 4) 224 | let stringFraction = BDouble("1" over: "3421342675925672365438867862653658268376582356831563158967")! 225 | ``` 226 | 227 | ### BDouble offers these struct methods 228 | ```swift 229 | let bigD = BDouble(-12.32) 230 | 231 | bigD.description // Returns "-308/25" 232 | => print(bigD) // prints "-308/25" 233 | 234 | 235 | bigD.minimize() // Divides numerator and denominator by their gcd for storage and operation efficiency, usually not neccesary, because of automatic minimization 236 | 237 | bigD.rawData() // Returns internal structure 238 | ``` 239 | 240 | ## The following Operators work with BDouble 241 | ```swift 242 | // Needs more operators, interoperability with BInt 243 | 244 | // Addition 245 | BDouble + BDouble // Returns BDouble 246 | 247 | // Subtraction 248 | BDouble - BDouble // Returns BDouble 249 | 250 | // Multiplication 251 | BDouble * BDouble // Returns BDouble 252 | 253 | // Division 254 | BDouble / BDouble // Returns BDouble 255 | 256 | // Comparing 257 | BDouble < BDouble 258 | /* 259 | Important: 260 | a < b <==> b > a 261 | a <= b <==> b >= a 262 | but: 263 | a < b <==> !(a >= b) 264 | a <= b <==> !(a > b) 265 | */ 266 | 267 | // More will follow 268 | ``` 269 | 270 | 271 | 272 | # About performance 273 | BInt about twice as fast as mini-gmp, as of now (not counting the normal gmp, because it needs to be installed and is not portable). For example, BInt can add numbers about 2 times faster than GMP (272ms vs 530ms for fib(100,000)), and multiplication is more than twice as fast. When given the task of calculating and printing factorials successively, BInt performs significantly better than GMP. In addition, GMP is significantly harder to use, while BInt offers an intuitive interface. 274 | 275 | 276 | 277 | # Contributing 278 | 1. Fork it! 279 | 2. Create your feature branch: `git checkout -b my-new-feature` 280 | 3. Commit your changes: `git commit -am 'Add some feature'` 281 | 4. Push to the branch: `git push origin my-new-feature` 282 | 5. Submit a pull request :D 283 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions/Int.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Int Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Int

134 |
135 |
136 |
@frozen
137 | extension Int: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(floatLiteral:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    public init(floatLiteral value: Double)
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/Extensions/Double.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Double Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Double

134 |
135 |
136 |
@frozen
137 | extension Double: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(_:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    init<T>(_ n: T) where T : NumericType
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions/Double.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Double Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Double

134 |
135 |
136 |
@frozen
137 | extension Double: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(_:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    init<T>(_ n: T) where T : NumericType
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/css/jazzy.css: -------------------------------------------------------------------------------- 1 | *, *:before, *:after { 2 | box-sizing: inherit; } 3 | 4 | body { 5 | margin: 0; 6 | background: #fff; 7 | color: #333; 8 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 9 | letter-spacing: .2px; 10 | -webkit-font-smoothing: antialiased; 11 | box-sizing: border-box; } 12 | 13 | h1 { 14 | font-size: 2rem; 15 | font-weight: 700; 16 | margin: 1.275em 0 0.6em; } 17 | 18 | h2 { 19 | font-size: 1.75rem; 20 | font-weight: 700; 21 | margin: 1.275em 0 0.3em; } 22 | 23 | h3 { 24 | font-size: 1.5rem; 25 | font-weight: 700; 26 | margin: 1em 0 0.3em; } 27 | 28 | h4 { 29 | font-size: 1.25rem; 30 | font-weight: 700; 31 | margin: 1.275em 0 0.85em; } 32 | 33 | h5 { 34 | font-size: 1rem; 35 | font-weight: 700; 36 | margin: 1.275em 0 0.85em; } 37 | 38 | h6 { 39 | font-size: 1rem; 40 | font-weight: 700; 41 | margin: 1.275em 0 0.85em; 42 | color: #777; } 43 | 44 | p { 45 | margin: 0 0 1em; } 46 | 47 | ul, ol { 48 | padding: 0 0 0 2em; 49 | margin: 0 0 0.85em; } 50 | 51 | blockquote { 52 | margin: 0 0 0.85em; 53 | padding: 0 15px; 54 | color: #858585; 55 | border-left: 4px solid #e5e5e5; } 56 | 57 | img { 58 | max-width: 100%; } 59 | 60 | a { 61 | color: #4183c4; 62 | text-decoration: none; } 63 | a:hover, a:focus { 64 | outline: 0; 65 | text-decoration: underline; } 66 | a.discouraged { 67 | text-decoration: line-through; } 68 | a.discouraged:hover, a.discouraged:focus { 69 | text-decoration: underline line-through; } 70 | 71 | table { 72 | background: #fff; 73 | width: 100%; 74 | border-collapse: collapse; 75 | border-spacing: 0; 76 | overflow: auto; 77 | margin: 0 0 0.85em; } 78 | 79 | tr:nth-child(2n) { 80 | background-color: #fbfbfb; } 81 | 82 | th, td { 83 | padding: 6px 13px; 84 | border: 1px solid #ddd; } 85 | 86 | pre { 87 | margin: 0 0 1.275em; 88 | padding: .85em 1em; 89 | overflow: auto; 90 | background: #f7f7f7; 91 | font-size: .85em; 92 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 93 | 94 | code { 95 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 96 | 97 | p > code, li > code { 98 | background: #f7f7f7; 99 | padding: .2em; } 100 | p > code:before, p > code:after, li > code:before, li > code:after { 101 | letter-spacing: -.2em; 102 | content: "\00a0"; } 103 | 104 | pre code { 105 | padding: 0; 106 | white-space: pre; } 107 | 108 | .content-wrapper { 109 | display: flex; 110 | flex-direction: column; } 111 | @media (min-width: 768px) { 112 | .content-wrapper { 113 | flex-direction: row; } } 114 | 115 | .header { 116 | display: flex; 117 | padding: 8px; 118 | font-size: 0.875em; 119 | background: #444; 120 | color: #999; } 121 | 122 | .header-col { 123 | margin: 0; 124 | padding: 0 8px; } 125 | 126 | .header-col--primary { 127 | flex: 1; } 128 | 129 | .header-link { 130 | color: #fff; } 131 | 132 | .header-icon { 133 | padding-right: 6px; 134 | vertical-align: -4px; 135 | height: 16px; } 136 | 137 | .breadcrumbs { 138 | font-size: 0.875em; 139 | padding: 8px 16px; 140 | margin: 0; 141 | background: #fbfbfb; 142 | border-bottom: 1px solid #ddd; } 143 | 144 | .carat { 145 | height: 10px; 146 | margin: 0 5px; } 147 | 148 | .navigation { 149 | order: 2; } 150 | @media (min-width: 768px) { 151 | .navigation { 152 | order: 1; 153 | width: 25%; 154 | max-width: 300px; 155 | padding-bottom: 64px; 156 | overflow: hidden; 157 | word-wrap: normal; 158 | background: #fbfbfb; 159 | border-right: 1px solid #ddd; } } 160 | 161 | .nav-groups { 162 | list-style-type: none; 163 | padding-left: 0; } 164 | 165 | .nav-group-name { 166 | border-bottom: 1px solid #ddd; 167 | padding: 8px 0 8px 16px; } 168 | 169 | .nav-group-name-link { 170 | color: #333; } 171 | 172 | .nav-group-tasks { 173 | margin: 8px 0; 174 | padding: 0 0 0 8px; } 175 | 176 | .nav-group-task { 177 | font-size: 1em; 178 | list-style-type: none; 179 | white-space: nowrap; } 180 | 181 | .nav-group-task-link { 182 | color: #808080; } 183 | 184 | .main-content { 185 | order: 1; } 186 | @media (min-width: 768px) { 187 | .main-content { 188 | order: 2; 189 | flex: 1; 190 | padding-bottom: 60px; } } 191 | 192 | .section { 193 | padding: 0 32px; 194 | border-bottom: 1px solid #ddd; } 195 | 196 | .section-content { 197 | max-width: 834px; 198 | margin: 0 auto; 199 | padding: 16px 0; } 200 | 201 | .section-name { 202 | color: #666; 203 | display: block; } 204 | 205 | .declaration .highlight { 206 | overflow-x: initial; 207 | padding: 8px 0; 208 | margin: 0; 209 | background-color: transparent; 210 | border: none; } 211 | 212 | .task-group-section { 213 | border-top: 1px solid #ddd; } 214 | 215 | .task-group { 216 | padding-top: 0px; } 217 | 218 | .task-name-container a[name]:before { 219 | content: ""; 220 | display: block; } 221 | 222 | .item-container { 223 | padding: 0; } 224 | 225 | .item { 226 | padding-top: 8px; 227 | width: 100%; 228 | list-style-type: none; } 229 | .item a[name]:before { 230 | content: ""; 231 | display: block; } 232 | .item .token, .item .direct-link { 233 | padding-left: 3px; 234 | margin-left: 0px; 235 | font-size: 1rem; } 236 | .item .declaration-note { 237 | font-size: .85em; 238 | color: #808080; 239 | font-style: italic; } 240 | 241 | .pointer-container { 242 | border-bottom: 1px solid #ddd; 243 | left: -23px; 244 | padding-bottom: 13px; 245 | position: relative; 246 | width: 110%; } 247 | 248 | .pointer { 249 | left: 21px; 250 | top: 7px; 251 | display: block; 252 | position: absolute; 253 | width: 12px; 254 | height: 12px; 255 | border-left: 1px solid #ddd; 256 | border-top: 1px solid #ddd; 257 | background: #fff; 258 | transform: rotate(45deg); } 259 | 260 | .height-container { 261 | display: none; 262 | position: relative; 263 | width: 100%; 264 | overflow: hidden; } 265 | .height-container .section { 266 | background: #fff; 267 | border: 1px solid #ddd; 268 | border-top-width: 0; 269 | padding-top: 10px; 270 | padding-bottom: 5px; 271 | padding: 8px 16px; } 272 | 273 | .aside, .language { 274 | padding: 6px 12px; 275 | margin: 12px 0; 276 | border-left: 5px solid #dddddd; 277 | overflow-y: hidden; } 278 | .aside .aside-title, .language .aside-title { 279 | font-size: 9px; 280 | letter-spacing: 2px; 281 | text-transform: uppercase; 282 | padding-bottom: 0; 283 | margin: 0; 284 | color: #aaa; 285 | -webkit-user-select: none; } 286 | .aside p:last-child, .language p:last-child { 287 | margin-bottom: 0; } 288 | 289 | .language { 290 | border-left: 5px solid #cde9f4; } 291 | .language .aside-title { 292 | color: #4183c4; } 293 | 294 | .aside-warning, .aside-deprecated, .aside-unavailable { 295 | border-left: 5px solid #ff6666; } 296 | .aside-warning .aside-title, .aside-deprecated .aside-title, .aside-unavailable .aside-title { 297 | color: #ff0000; } 298 | 299 | .graybox { 300 | border-collapse: collapse; 301 | width: 100%; } 302 | .graybox p { 303 | margin: 0; 304 | word-break: break-word; 305 | min-width: 50px; } 306 | .graybox td { 307 | border: 1px solid #ddd; 308 | padding: 5px 25px 5px 10px; 309 | vertical-align: middle; } 310 | .graybox tr td:first-of-type { 311 | text-align: right; 312 | padding: 7px; 313 | vertical-align: top; 314 | word-break: normal; 315 | width: 40px; } 316 | 317 | .slightly-smaller { 318 | font-size: 0.9em; } 319 | 320 | .footer { 321 | padding: 8px 16px; 322 | background: #444; 323 | color: #ddd; 324 | font-size: 0.8em; } 325 | .footer p { 326 | margin: 8px 0; } 327 | .footer a { 328 | color: #fff; } 329 | 330 | html.dash .header, html.dash .breadcrumbs, html.dash .navigation { 331 | display: none; } 332 | 333 | html.dash .height-container { 334 | display: block; } 335 | 336 | form[role=search] input { 337 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 338 | font-size: 14px; 339 | line-height: 24px; 340 | padding: 0 10px; 341 | margin: 0; 342 | border: none; 343 | border-radius: 1em; } 344 | .loading form[role=search] input { 345 | background: white url(../img/spinner.gif) center right 4px no-repeat; } 346 | 347 | form[role=search] .tt-menu { 348 | margin: 0; 349 | min-width: 300px; 350 | background: #fbfbfb; 351 | color: #333; 352 | border: 1px solid #ddd; } 353 | 354 | form[role=search] .tt-highlight { 355 | font-weight: bold; } 356 | 357 | form[role=search] .tt-suggestion { 358 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 359 | padding: 0 8px; } 360 | form[role=search] .tt-suggestion span { 361 | display: table-cell; 362 | white-space: nowrap; } 363 | form[role=search] .tt-suggestion .doc-parent-name { 364 | width: 100%; 365 | text-align: right; 366 | font-weight: normal; 367 | font-size: 0.9em; 368 | padding-left: 16px; } 369 | 370 | form[role=search] .tt-suggestion:hover, 371 | form[role=search] .tt-suggestion.tt-cursor { 372 | cursor: pointer; 373 | background-color: #4183c4; 374 | color: #fff; } 375 | 376 | form[role=search] .tt-suggestion:hover .doc-parent-name, 377 | form[role=search] .tt-suggestion.tt-cursor .doc-parent-name { 378 | color: #fff; } 379 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/css/jazzy.css: -------------------------------------------------------------------------------- 1 | *, *:before, *:after { 2 | box-sizing: inherit; } 3 | 4 | body { 5 | margin: 0; 6 | background: #fff; 7 | color: #333; 8 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 9 | letter-spacing: .2px; 10 | -webkit-font-smoothing: antialiased; 11 | box-sizing: border-box; } 12 | 13 | h1 { 14 | font-size: 2rem; 15 | font-weight: 700; 16 | margin: 1.275em 0 0.6em; } 17 | 18 | h2 { 19 | font-size: 1.75rem; 20 | font-weight: 700; 21 | margin: 1.275em 0 0.3em; } 22 | 23 | h3 { 24 | font-size: 1.5rem; 25 | font-weight: 700; 26 | margin: 1em 0 0.3em; } 27 | 28 | h4 { 29 | font-size: 1.25rem; 30 | font-weight: 700; 31 | margin: 1.275em 0 0.85em; } 32 | 33 | h5 { 34 | font-size: 1rem; 35 | font-weight: 700; 36 | margin: 1.275em 0 0.85em; } 37 | 38 | h6 { 39 | font-size: 1rem; 40 | font-weight: 700; 41 | margin: 1.275em 0 0.85em; 42 | color: #777; } 43 | 44 | p { 45 | margin: 0 0 1em; } 46 | 47 | ul, ol { 48 | padding: 0 0 0 2em; 49 | margin: 0 0 0.85em; } 50 | 51 | blockquote { 52 | margin: 0 0 0.85em; 53 | padding: 0 15px; 54 | color: #858585; 55 | border-left: 4px solid #e5e5e5; } 56 | 57 | img { 58 | max-width: 100%; } 59 | 60 | a { 61 | color: #4183c4; 62 | text-decoration: none; } 63 | a:hover, a:focus { 64 | outline: 0; 65 | text-decoration: underline; } 66 | a.discouraged { 67 | text-decoration: line-through; } 68 | a.discouraged:hover, a.discouraged:focus { 69 | text-decoration: underline line-through; } 70 | 71 | table { 72 | background: #fff; 73 | width: 100%; 74 | border-collapse: collapse; 75 | border-spacing: 0; 76 | overflow: auto; 77 | margin: 0 0 0.85em; } 78 | 79 | tr:nth-child(2n) { 80 | background-color: #fbfbfb; } 81 | 82 | th, td { 83 | padding: 6px 13px; 84 | border: 1px solid #ddd; } 85 | 86 | pre { 87 | margin: 0 0 1.275em; 88 | padding: .85em 1em; 89 | overflow: auto; 90 | background: #f7f7f7; 91 | font-size: .85em; 92 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 93 | 94 | code { 95 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 96 | 97 | p > code, li > code { 98 | background: #f7f7f7; 99 | padding: .2em; } 100 | p > code:before, p > code:after, li > code:before, li > code:after { 101 | letter-spacing: -.2em; 102 | content: "\00a0"; } 103 | 104 | pre code { 105 | padding: 0; 106 | white-space: pre; } 107 | 108 | .content-wrapper { 109 | display: flex; 110 | flex-direction: column; } 111 | @media (min-width: 768px) { 112 | .content-wrapper { 113 | flex-direction: row; } } 114 | 115 | .header { 116 | display: flex; 117 | padding: 8px; 118 | font-size: 0.875em; 119 | background: #444; 120 | color: #999; } 121 | 122 | .header-col { 123 | margin: 0; 124 | padding: 0 8px; } 125 | 126 | .header-col--primary { 127 | flex: 1; } 128 | 129 | .header-link { 130 | color: #fff; } 131 | 132 | .header-icon { 133 | padding-right: 6px; 134 | vertical-align: -4px; 135 | height: 16px; } 136 | 137 | .breadcrumbs { 138 | font-size: 0.875em; 139 | padding: 8px 16px; 140 | margin: 0; 141 | background: #fbfbfb; 142 | border-bottom: 1px solid #ddd; } 143 | 144 | .carat { 145 | height: 10px; 146 | margin: 0 5px; } 147 | 148 | .navigation { 149 | order: 2; } 150 | @media (min-width: 768px) { 151 | .navigation { 152 | order: 1; 153 | width: 25%; 154 | max-width: 300px; 155 | padding-bottom: 64px; 156 | overflow: hidden; 157 | word-wrap: normal; 158 | background: #fbfbfb; 159 | border-right: 1px solid #ddd; } } 160 | 161 | .nav-groups { 162 | list-style-type: none; 163 | padding-left: 0; } 164 | 165 | .nav-group-name { 166 | border-bottom: 1px solid #ddd; 167 | padding: 8px 0 8px 16px; } 168 | 169 | .nav-group-name-link { 170 | color: #333; } 171 | 172 | .nav-group-tasks { 173 | margin: 8px 0; 174 | padding: 0 0 0 8px; } 175 | 176 | .nav-group-task { 177 | font-size: 1em; 178 | list-style-type: none; 179 | white-space: nowrap; } 180 | 181 | .nav-group-task-link { 182 | color: #808080; } 183 | 184 | .main-content { 185 | order: 1; } 186 | @media (min-width: 768px) { 187 | .main-content { 188 | order: 2; 189 | flex: 1; 190 | padding-bottom: 60px; } } 191 | 192 | .section { 193 | padding: 0 32px; 194 | border-bottom: 1px solid #ddd; } 195 | 196 | .section-content { 197 | max-width: 834px; 198 | margin: 0 auto; 199 | padding: 16px 0; } 200 | 201 | .section-name { 202 | color: #666; 203 | display: block; } 204 | 205 | .declaration .highlight { 206 | overflow-x: initial; 207 | padding: 8px 0; 208 | margin: 0; 209 | background-color: transparent; 210 | border: none; } 211 | 212 | .task-group-section { 213 | border-top: 1px solid #ddd; } 214 | 215 | .task-group { 216 | padding-top: 0px; } 217 | 218 | .task-name-container a[name]:before { 219 | content: ""; 220 | display: block; } 221 | 222 | .item-container { 223 | padding: 0; } 224 | 225 | .item { 226 | padding-top: 8px; 227 | width: 100%; 228 | list-style-type: none; } 229 | .item a[name]:before { 230 | content: ""; 231 | display: block; } 232 | .item .token, .item .direct-link { 233 | padding-left: 3px; 234 | margin-left: 0px; 235 | font-size: 1rem; } 236 | .item .declaration-note { 237 | font-size: .85em; 238 | color: #808080; 239 | font-style: italic; } 240 | 241 | .pointer-container { 242 | border-bottom: 1px solid #ddd; 243 | left: -23px; 244 | padding-bottom: 13px; 245 | position: relative; 246 | width: 110%; } 247 | 248 | .pointer { 249 | left: 21px; 250 | top: 7px; 251 | display: block; 252 | position: absolute; 253 | width: 12px; 254 | height: 12px; 255 | border-left: 1px solid #ddd; 256 | border-top: 1px solid #ddd; 257 | background: #fff; 258 | transform: rotate(45deg); } 259 | 260 | .height-container { 261 | display: none; 262 | position: relative; 263 | width: 100%; 264 | overflow: hidden; } 265 | .height-container .section { 266 | background: #fff; 267 | border: 1px solid #ddd; 268 | border-top-width: 0; 269 | padding-top: 10px; 270 | padding-bottom: 5px; 271 | padding: 8px 16px; } 272 | 273 | .aside, .language { 274 | padding: 6px 12px; 275 | margin: 12px 0; 276 | border-left: 5px solid #dddddd; 277 | overflow-y: hidden; } 278 | .aside .aside-title, .language .aside-title { 279 | font-size: 9px; 280 | letter-spacing: 2px; 281 | text-transform: uppercase; 282 | padding-bottom: 0; 283 | margin: 0; 284 | color: #aaa; 285 | -webkit-user-select: none; } 286 | .aside p:last-child, .language p:last-child { 287 | margin-bottom: 0; } 288 | 289 | .language { 290 | border-left: 5px solid #cde9f4; } 291 | .language .aside-title { 292 | color: #4183c4; } 293 | 294 | .aside-warning, .aside-deprecated, .aside-unavailable { 295 | border-left: 5px solid #ff6666; } 296 | .aside-warning .aside-title, .aside-deprecated .aside-title, .aside-unavailable .aside-title { 297 | color: #ff0000; } 298 | 299 | .graybox { 300 | border-collapse: collapse; 301 | width: 100%; } 302 | .graybox p { 303 | margin: 0; 304 | word-break: break-word; 305 | min-width: 50px; } 306 | .graybox td { 307 | border: 1px solid #ddd; 308 | padding: 5px 25px 5px 10px; 309 | vertical-align: middle; } 310 | .graybox tr td:first-of-type { 311 | text-align: right; 312 | padding: 7px; 313 | vertical-align: top; 314 | word-break: normal; 315 | width: 40px; } 316 | 317 | .slightly-smaller { 318 | font-size: 0.9em; } 319 | 320 | .footer { 321 | padding: 8px 16px; 322 | background: #444; 323 | color: #ddd; 324 | font-size: 0.8em; } 325 | .footer p { 326 | margin: 8px 0; } 327 | .footer a { 328 | color: #fff; } 329 | 330 | html.dash .header, html.dash .breadcrumbs, html.dash .navigation { 331 | display: none; } 332 | 333 | html.dash .height-container { 334 | display: block; } 335 | 336 | form[role=search] input { 337 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 338 | font-size: 14px; 339 | line-height: 24px; 340 | padding: 0 10px; 341 | margin: 0; 342 | border: none; 343 | border-radius: 1em; } 344 | .loading form[role=search] input { 345 | background: white url(../img/spinner.gif) center right 4px no-repeat; } 346 | 347 | form[role=search] .tt-menu { 348 | margin: 0; 349 | min-width: 300px; 350 | background: #fbfbfb; 351 | color: #333; 352 | border: 1px solid #ddd; } 353 | 354 | form[role=search] .tt-highlight { 355 | font-weight: bold; } 356 | 357 | form[role=search] .tt-suggestion { 358 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 359 | padding: 0 8px; } 360 | form[role=search] .tt-suggestion span { 361 | display: table-cell; 362 | white-space: nowrap; } 363 | form[role=search] .tt-suggestion .doc-parent-name { 364 | width: 100%; 365 | text-align: right; 366 | font-weight: normal; 367 | font-size: 0.9em; 368 | padding-left: 16px; } 369 | 370 | form[role=search] .tt-suggestion:hover, 371 | form[role=search] .tt-suggestion.tt-cursor { 372 | cursor: pointer; 373 | background-color: #4183c4; 374 | color: #fff; } 375 | 376 | form[role=search] .tt-suggestion:hover .doc-parent-name, 377 | form[role=search] .tt-suggestion.tt-cursor .doc-parent-name { 378 | color: #fff; } 379 | -------------------------------------------------------------------------------- /docs/Extensions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Extensions Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Extensions

134 |

The following extensions are available globally.

135 | 136 |
137 |
138 | 139 |
140 |
141 |
142 |
    143 |
  • 144 |
    145 | 146 | 147 | 148 | Double 149 | 150 |
    151 |
    152 |
    153 |
    154 |
    155 |
    156 | 157 | See more 158 |
    159 |
    160 |

    Declaration

    161 |
    162 |

    Swift

    163 |
    @frozen
    164 | extension Double: NumericType
    165 | 166 |
    167 |
    168 |
    169 |
    170 |
  • 171 |
  • 172 |
    173 | 174 | 175 | 176 | Int 177 | 178 |
    179 |
    180 |
    181 |
    182 |
    183 |
    184 | 185 | See more 186 |
    187 |
    188 |

    Declaration

    189 |
    190 |

    Swift

    191 |
    @frozen
    192 | extension Int: NumericType
    193 | 194 |
    195 |
    196 |
    197 |
    198 |
  • 199 |
200 |
201 |
202 |
203 | 204 |
205 |
206 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Extensions Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Extensions

134 |

The following extensions are available globally.

135 | 136 |
137 |
138 | 139 |
140 |
141 |
142 |
    143 |
  • 144 |
    145 | 146 | 147 | 148 | Double 149 | 150 |
    151 |
    152 |
    153 |
    154 |
    155 |
    156 | 157 | See more 158 |
    159 |
    160 |

    Declaration

    161 |
    162 |

    Swift

    163 |
    @frozen
    164 | extension Double: NumericType
    165 | 166 |
    167 |
    168 |
    169 |
    170 |
  • 171 |
  • 172 |
    173 | 174 | 175 | 176 | Int 177 | 178 |
    179 |
    180 |
    181 |
    182 |
    183 |
    184 | 185 | See more 186 |
    187 |
    188 |

    Declaration

    189 |
    190 |

    Swift

    191 |
    @frozen
    192 | extension Int: NumericType
    193 | 194 |
    195 |
    196 |
    197 |
    198 |
  • 199 |
200 |
201 |
202 |
203 | 204 |
205 |
206 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /Tools/MG Math.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Basic Math.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 03.04.2015. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | #if os(Linux) 10 | import Glibc 11 | import CBSD 12 | #endif 13 | 14 | import Foundation 15 | 16 | infix operator ** 17 | 18 | func **(lhs: Double, rhs: Double) -> Double { return pow(lhs, rhs) } 19 | func **(lhs: Int, rhs: Double) -> Double { return pow(Double(lhs), rhs) } 20 | func **(lhs: Double, rhs: Int) -> Double { return pow(lhs, Double(rhs)) } 21 | func **(lhs: Int, rhs: Int) -> Int 22 | { 23 | var res = 1 24 | for _ in 0.. Double { return lhs + Double(rhs) } 33 | func +(lhs: Int, rhs: Double) -> Double { return Double(lhs) + rhs } 34 | 35 | func -(lhs: Double, rhs: Int) -> Double { return lhs - Double(rhs) } 36 | func -(lhs: Int, rhs: Double) -> Double { return Double(lhs) - rhs } 37 | 38 | func *(lhs: Double, rhs: Int) -> Double { return lhs * Double(rhs) } 39 | func *(lhs: Int, rhs: Double) -> Double { return Double(lhs) * rhs } 40 | 41 | func /(lhs: Double, rhs: Int) -> Double { return lhs / Double(rhs) } 42 | func /(lhs: Int, rhs: Double) -> Double { return Double(lhs) / rhs } 43 | 44 | 45 | 46 | public class math 47 | { 48 | init() 49 | { 50 | fatalError("math is purely static, you can't make an instance of it.") 51 | } 52 | 53 | /// Returns the logarithm of n to the base of b. 54 | public static func lg(base b: Double, _ n: Double) -> Double 55 | { 56 | return log2(Double(n)) / log2(Double(b)) 57 | } 58 | 59 | /// Returns the logarithm of n to the base of b. 60 | public static func lg(base b: Int, _ n: Double) -> Double 61 | { 62 | return math.lg(base: Double(b), n) 63 | } 64 | 65 | /// Returns the logarithm of n to the base of b. 66 | public static func lg(base b: Double, _ n: Int) -> Double 67 | { 68 | return math.lg(base: b, Double(n)) 69 | } 70 | 71 | /// Returns the logarithm of n to the base of b. 72 | public static func lg(base b: Int, _ n: Int) -> Double 73 | { 74 | return math.lg(base: Double(b), Double(n)) 75 | } 76 | 77 | 78 | /// Returns the binomial coefficient of n and k. 79 | public static func binomial(_ n: Int, _ k: Int) -> Int 80 | { 81 | if k == 0 { return 1 } 82 | if n == 0 { return 0 } 83 | return math.binomial(n - 1, k) + math.binomial(n - 1, k - 1) 84 | } 85 | 86 | /// Returns the greatest common divisor of a and b. 87 | public static func gcd(_ a: Int, _ b: Int) -> Int 88 | { 89 | if b == 0 { return a } 90 | return math.gcd(b, a % b) 91 | } 92 | 93 | /// Returns the lest common multiple of a and b. 94 | public static func lcm(_ a: Int, _ b: Int) -> Int 95 | { 96 | return (a / math.gcd(a, b)) * b 97 | } 98 | 99 | /** 100 | * Returns the number of digits of the input in the specified base. 101 | * Positive and negative numbers are treated equally. 102 | */ 103 | public static func digitsCount(base b: Int, _ n: Int) -> Int 104 | { 105 | var n = abs(n) 106 | var count = 0 107 | 108 | while n != 0 109 | { 110 | n /= b 111 | count += 1 112 | } 113 | 114 | return count 115 | } 116 | 117 | // Returns true iff n is a prime number. 118 | public static func isPrime(_ n: Int) -> Bool 119 | { 120 | if n <= 3 { return n > 1 } 121 | 122 | if n % 2 == 0 || n % 3 == 0 { return false } 123 | 124 | var i = 5 125 | while i * i <= n 126 | { 127 | if n % i == 0 || n % (i + 2) == 0 128 | { 129 | return false 130 | } 131 | i += 6 132 | } 133 | return true 134 | } 135 | 136 | /// Returns the n-th prime number. The first one is 2, etc. 137 | public static func getPrime(_ n: Int) -> Int 138 | { 139 | precondition(n > 0, "There is no \(n)-th prime number") 140 | 141 | var (prime, primeCount) = (2, 1) 142 | 143 | while primeCount != n 144 | { 145 | prime += 1 146 | if math.isPrime(prime) { primeCount += 1 } 147 | } 148 | 149 | return prime 150 | } 151 | 152 | 153 | 154 | /// Returns all primes that are smaller or equal to n. Works with the Sieve of Eratosthenes. 155 | public static func primesThrough(_ n: Int) -> [Int] 156 | { 157 | if n < 2 { return [] } 158 | 159 | // represent numbers 3,5,... that are <= n 160 | var A = [Bool](repeating: true, count: n >> 1) 161 | 162 | var (i, j, c) = (3, 0, 0) 163 | while i * i <= n 164 | { 165 | if A[(i >> 1) - 1] 166 | { 167 | (c, j) = (1, i * i) 168 | while j <= n 169 | { 170 | if j % 2 != 0 { A[(j >> 1) - 1] = false } 171 | j = i * (i + c) 172 | c += 1 173 | } 174 | } 175 | i += 2 176 | } 177 | 178 | var res = [2] 179 | 180 | i = 3 181 | while i <= n 182 | { 183 | if A[(i >> 1) - 1] { res.append(i) } 184 | i += 2 185 | } 186 | 187 | return res 188 | } 189 | 190 | 191 | /// Increments the input parameter until it is the next bigger prime. 192 | public static func nextPrime( _ n: inout Int) 193 | { 194 | repeat { n += 1 } while !math.isPrime(n) 195 | } 196 | 197 | /// Returns a random integer within the specified range. The maximum range size is 2**32 - 1 198 | public static func random(_ range: Range) -> Int 199 | { 200 | let offset = Int(range.lowerBound) 201 | let delta = UInt32(range.upperBound - range.lowerBound) 202 | 203 | return offset + Int(arc4random_uniform(delta)) 204 | } 205 | 206 | /// Returns a random integer within the specified closed range. 207 | public static func random(_ range: ClosedRange) -> Int 208 | { 209 | return math.random(Range(range)) 210 | } 211 | 212 | /// Returns an array filled with n random integers within the specified range. 213 | public static func random(_ range: Range, count: Int) -> [Int] 214 | { 215 | return [Int](repeating: 0, count: count).map{ _ in math.random(range) } 216 | } 217 | 218 | /// Returns an array filled with n random integers within the specified closed range. 219 | public static func random(_ range: ClosedRange, count: Int) -> [Int] 220 | { 221 | return math.random(Range(range), count: count) 222 | } 223 | 224 | /// Returns a random Double within the specified closed range. 225 | public static func random(_ range: ClosedRange) -> Double 226 | { 227 | let offset = range.lowerBound 228 | let delta = range.upperBound - range.lowerBound 229 | 230 | return offset + ((delta * Double(arc4random())) / Double(UInt32.max)) 231 | } 232 | 233 | /// Returns an array filled with n random Doubles within the specified closed range. 234 | public static func random(_ range: ClosedRange, count: Int) -> [Double] 235 | { 236 | return [Double](repeating: 0, count: count).map{ _ in math.random(range) } 237 | } 238 | 239 | /// Calculate a random value from a standard normal distribution with mean 0 and variance 1. 240 | public static func randomStandardNormalDistributed() -> Double 241 | { 242 | var (x, y, l) = (0.0, 0.0, 0.0) 243 | 244 | while l >= 1.0 || l == 0.0 245 | { 246 | x = math.random(-1.0...1.0) 247 | y = math.random(-1.0...1.0) 248 | l = pow(x, 2.0) + pow(y, 2.0) 249 | } 250 | 251 | return y * sqrt((-2.0 * log(l)) / l) 252 | } 253 | 254 | 255 | /// Generate count many random values from a normal distribution with the given mean and variance. 256 | public static func randomFromNormalDist(_ mean: Double, _ variance: Double, _ count: Int) -> [Double] 257 | { 258 | let res = [Double](repeating: mean, count: count) 259 | 260 | return res.map{ $0 + (variance * math.randomStandardNormalDistributed()) 261 | } 262 | } 263 | 264 | /// Multiple cases to select the instance space of a random string. 265 | public enum LetterSet 266 | { 267 | case lowerCase 268 | case upperCase 269 | case numbers 270 | case specialSymbols 271 | case all 272 | } 273 | 274 | /** 275 | Creates a random String from one or multiple sets of 276 | letters. 277 | 278 | - Parameter length: Number of characters in random string. 279 | 280 | - Parameter letterSet: Specify desired letters as variadic 281 | parameters: 282 | - .All 283 | - .Numbers 284 | - .LowerCase 285 | - .UpperCase 286 | - .SpecialSymbols 287 | */ 288 | public static func randomString(_ length: Int, letterSet: LetterSet...) -> String 289 | { 290 | var letters = [String]() 291 | var ranges = [CountableClosedRange]() 292 | 293 | for ele in letterSet 294 | { 295 | switch ele 296 | { 297 | case .all: 298 | ranges.append(33...126) 299 | 300 | case .numbers: 301 | ranges.append(48...57) 302 | 303 | case .lowerCase: 304 | ranges.append(97...122) 305 | 306 | case .upperCase: 307 | ranges.append(65...90) 308 | 309 | case .specialSymbols: 310 | ranges += [33...47, 58...64, 91...96, 123...126] 311 | } 312 | } 313 | 314 | for range in ranges 315 | { 316 | for symbol in range 317 | { 318 | letters.append(String(describing: UnicodeScalar(symbol)!)) 319 | } 320 | } 321 | 322 | var res = "" 323 | 324 | for _ in 0.. [(factor: Int, count: Int)] 334 | { 335 | if math.isPrime(n) || n == 1 { return [(n, 1)] } 336 | 337 | var n = n 338 | var res = [(factor: Int, count: Int)]() 339 | var nthPrime = 1 340 | 341 | while true 342 | { 343 | math.nextPrime(&nthPrime) 344 | 345 | if n % nthPrime == 0 346 | { 347 | var times = 1 348 | n /= nthPrime 349 | 350 | while n % nthPrime == 0 351 | { 352 | times += 1 353 | n /= nthPrime 354 | } 355 | 356 | res.append((nthPrime, times)) 357 | 358 | if n == 1 { return res } 359 | 360 | if math.isPrime(n) 361 | { 362 | res.append((n, 1)) 363 | return res 364 | } 365 | } 366 | } 367 | } 368 | } 369 | --------------------------------------------------------------------------------